Repetitive Structures for …. statement while …. statement do….while statement
f or…statement Syntax: for (initial; condition; increment/decrement) { statement(s); }
Example 1: #include< stdio.h > int main() { int counter; for(counter=1;counter<=10;counter++) printf("%d\n", counter); return 0; }
while…statement Syntax: while (condition) { statement (s); }
Example 2: #include< stdio.h > int main() { int counter =1; while (counter<=150) { printf("%d\n", counter); counter++; } return 0; }
do…while Syntax: do { statement(s); } while(condition);
Example 3 # #include< stdio.h > int main() { int counter=1; do { printf ("%d\n", counter); counter++; } while (counter<=10); return 0; }
Fundamental Input/output The printf(): Used for displaying Information on the Screen Examples: printf("An error has occurred!"); printf("\n The value of x is %d", x); Output: The value of x is 12
Most Frequently Used Escape Sequences Sequence Meaning \a Bell (alert) \b Backspace \n Newline \t Horizontal tab \\ Backslash \? Question mark \' Single quotation
Using Printf() Escape Sequences Sequence Meaning N The character n \n Newline \" The double quotation character " The start or end of a string
Using Printf() Conversion Specifiers Specifier Meaning Types Converted %c Single character Char %d Signed decimal integer int, short %ld Signed long decimal integer Long %f Decimal floating-point number float, double %s Character string char arrays %u Unsigned decimal integer unsigned int, unsigned short %lu Unsigned long decimal integer unsigned long
Puts() function puts("Hello, world."); Performs the same function as, printf("Hello, world.\n");
Inputting Numeric Data Scan () Function scanf("%d", &x); scanf("%f", &rate); scanf("%d %f", &x, &rate);
Read About! Flow Control , Repetitive Structures & Input/Output functions*. User Defined* & Pre-defined* Functions in C Study Carefully, Run all programs contained in the notes in the compiler of your choice to understand.