01 Session Printf
01 Session Printf
First Program in C
columns
columns
# include < stdio .h > co
columns
columns co
int main ( void )
columns
columns co
columns
columns
{ co
printf ( " Hello , World ! " ) ;
columns
columns co
columns
columns
return 0; co
columns
columns
} co
– Eg. a, B, t, &, ?, ..
– E.g. printf("Hello, World!") will display Hello, World! on the Console window.
printf()displays the string (i.e. all characters of the string) starting from the current cursor position.
Once a character is displayed, the cursor position is automatically advanced to the next character position
of the terminal window.
Execute the program in the Listing 1.2, to see the effect of \n.
\t can be used to align characters/text along with tab positions of the terminal across raws.
– Why the last line is not aligned with other two lines? Correct the program in the Listing 1.3 to
make all three lines aligned along a single column.
Exercise 1.4 Execute the program in Listing 1.2 and notice the effect of (\n).
Exercise 1.5 Execute the program in Listing 1.3 and observe the effect of \t).
Exercise 1.6 Modify the program in Listing 1.3 to observe the effect of other escape sequences given in Table
1.1.
2
Table 1.1: Escape sequences
1.5 Comments
Comments are part of the source code but ignored during the compilation and making the executable.
3
Listing 1.4: Comments are written between /* and */
columns
columns
/* This Program displays information on the Faculty of Engineering co
columns
columnsUniversity of Ruhuna co
*/
columns
columns co
columns
columns
# include < stdio .h > co
columns
columns co
columns
columns
int main ( void ) co
{ /* Begining of the Program */
columns
columns co
columns
columnsprintf ( " Faculty of Engineering , " ) ; /* Display Infomation */ co
columns
columnsprintf ( " University of Ruhuna is situated in Hapugala , Galle .\ n " ) ; co
columns
columns co
columns
columnsreturn 0; /* End of the program */ co
}
columns
columns co
columns
columns co
1.6 Assignments
1.1 Write a program to display the following output.
*******
*****
****
***
**
*
University of Ruhuna
Faculty of Engineering
======================
CONTINOUS ASSESSMENT MARKS
Module:EE5217 Measurements and Instrumentation
—-