You are on page 1of 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