0% found this document useful (0 votes)
47 views

Lecture 3

This document provides an overview of key concepts for writing C/C++ programs, including that programs are made up of statements ending with semicolons, variables must be declared before use, and output can be printed to the console using printf formatting strings. It also describes how to take user input during program execution using scanf, noting the ampersand is required before variables to pass their memory address.

Uploaded by

Mir Fida Nadeem
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Lecture 3

This document provides an overview of key concepts for writing C/C++ programs, including that programs are made up of statements ending with semicolons, variables must be declared before use, and output can be printed to the console using printf formatting strings. It also describes how to take user input during program execution using scanf, noting the ampersand is required before variables to pass their memory address.

Uploaded by

Mir Fida Nadeem
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Writing C/C++ Programs

 Instructions as statements
 Order of statements
 Each statement must end with a ;
 Blanks for readability or clarity
 Case-Sensitive

1
Variable Declaration
2

 Any variable used in the program must be declared


first before using it.
 int x;
 char my_Letter;
 float time;
 double Result;

2
Output function
 printf ( "<format string>", <list of variables> ) ;
 <format string> can contain,
Format String Identifier
Single Character %c
Integer %d
Float %f
Double %lf

3
Examples
4

 printf(“The Letter is %c”, ’k’);


 printf(“That pronounced as %s”, ’kay’);
 printf(“Integer Input is %d”, 2);
 printf(“Floating Point input is %f”,24.56);

4
Gross salary C Program

5
Input
 To make gross salary calculation program general,
the program ask the user to input value of hours
and payrate during execution
 scanf function is used to input value from user during
program execution

6
Gross salary C Program

7
Input function syntax

 Ampersand (&) before the variables in the scanf( )


function is a must.
 & is an ‘Address of’ operator
 It gives the location number used by the variable in
memory

8
9

 End

You might also like