Upcoming SlideShare
×

# C programming session 02

1,707 views

Published on

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
1,707
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
134
0
Likes
1
Embeds 0
No embeds

No notes for slide
• Begin the session by explaining the objectives of the session.
• Tell the students that they cannot create a useful programs without using the operators. A simple program such as adding two variables and showing the result needs the use of variables.
• Operator precedence is very important in a program. If the operator precedence is not considered then the program might produce an unexpected result. Give an example, which produces a result different from the expected result because of incorrect operator precedence.
• Use Slide 4 to test the student’s understanding on logical operators.
• Use Slide 7 to test the student’s understanding on unary operators.
• Use Slide 10 to test the student’s understanding on binary operators.
• Use this slide to test the student’s understanding on binary operators.
• Use this slide to test the student’s understanding on ternary operators.
• Use this slide to test the student’s understanding on increment/decrement operators.
• Explain definite and indefinite loops. Give some examples, which distinguish between definite and indefinite loops.
• The for loop consists of three parts : Initialization Condition Re-initialization (increment/decrement) In a for loop, after initialization, the condition is first checked. If the condition is valid, the body of the for loop is executed. For each iteration, re-initialization is done before the condition is checked again. Any or all of these parts may be left out of the construct. For example : for ( ; ; ) { } is an infinite loop (as there is no condition).
• Use this slide to test the student’s understanding on loops.
• Use this slide to test the student’s understanding on controlling the loop execution.
• When used with strings, the format string could be quite confusing. The statement: printf ( “%15.5s”, string) prints the first 5 characters of the string right-justified in 15 spaces. When used with floats, it represents the precision required.
• Use this slide to test the student’s understanding on formatted output.
• Use this slide to test the student’s understanding on formatted input.
• Use this slide to test the student’s understanding on formatted input-output.
• The output buffer is flushed only if it is full, or if the string to be printed contains a newline character at the end or if it is explicitly flushed using fflush () . The last option is used if the string does not contain a new line character. The string might not be displayed at the right place at the right time otherwise.
• Use this and the next 4 slides to summarize this session.
• ### C programming session 02

1. 1. <ul><li>In this session, you will learn to: </li></ul><ul><ul><li>Work with operators </li></ul></ul><ul><ul><li>Use loops </li></ul></ul><ul><ul><li>Use formatted input-output functions </li></ul></ul>Objectives
2. 2. <ul><li>An operator: </li></ul><ul><ul><li>Is a symbol used to command the computer to do mathematical or logical manipulations. </li></ul></ul><ul><ul><li>Operates on data and variables. </li></ul></ul><ul><li>C has a rich set of operators, which can be classified into following various categories: </li></ul><ul><ul><li>Relational operators </li></ul></ul><ul><ul><li>Logical operators </li></ul></ul><ul><ul><li>Unary operators </li></ul></ul><ul><ul><li>Binary operators </li></ul></ul><ul><ul><li>Ternary operator </li></ul></ul><ul><ul><li>Compound assignment operators </li></ul></ul><ul><ul><li>Increment/Decrement operators </li></ul></ul>Working with Operators
3. 3. <ul><li>Notations for logical operators in C are: </li></ul><ul><ul><li>Operator Notation </li></ul></ul><ul><ul><li> OR | | </li></ul></ul><ul><ul><li> AND && </li></ul></ul><ul><ul><li> NOT ! </li></ul></ul><ul><li>Operator precedence: </li></ul><ul><li>NOT (!) is evaluated before AND (&&), which is evaluated before OR (||). Brackets () are used to change this order. </li></ul>Logical Operators
4. 4. <ul><li>Write a function that accepts either y or n only as input. For any other character input, an appropriate error message should be displayed and the input is accepted again. </li></ul>Practice: 2.1
5. 5. <ul><li>Solution: </li></ul><ul><ul><li>#include<stdio.h> </li></ul></ul><ul><ul><ul><li>main() </li></ul></ul></ul><ul><ul><ul><li>{ char yn; </li></ul></ul></ul><ul><ul><ul><li>do { </li></ul></ul></ul><ul><ul><ul><li>puts(“Enter y/n (Yes/No)”); </li></ul></ul></ul><ul><ul><ul><li>yn=getchar (); </li></ul></ul></ul><ul><ul><ul><li>fflush (stdin); </li></ul></ul></ul><ul><ul><ul><li>if(yn!=’y’ && yn!=’n’) </li></ul></ul></ul><ul><ul><ul><li>puts(“Invalid input”); </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>while(yn!=’y’ && yn!=’n’); </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>Practice: 2.1 (Contd.)
6. 6. <ul><li>Unary Operators: </li></ul><ul><ul><li>Operates on a single operand. </li></ul></ul><ul><ul><li>Prefixed to an integer constant. </li></ul></ul><ul><ul><li>Tells the compiler to reverse the sign by subtracting the value (or variable) from zero. </li></ul></ul><ul><ul><li>Has the same effect as the – sign, which is used to indicate a number less than zero, for example -12. </li></ul></ul>Unary Operators
7. 7. <ul><li>Which of the following are valid? </li></ul><ul><ul><li>1. valuea=-12; /* valuea is int* / </li></ul></ul><ul><ul><li>2. valuea = - valueb – 12 /* valuea and valueb both are int */ </li></ul></ul>Practice: 2.2
8. 8. <ul><li>Solution: </li></ul><ul><ul><li>1. Valid </li></ul></ul><ul><ul><li>2. Valid </li></ul></ul>Practice: 2.2 (Contd.)
9. 9. <ul><li>Binary Operators: </li></ul><ul><ul><li>Operate on two operands. </li></ul></ul><ul><ul><li>Are as follows: </li></ul></ul><ul><ul><ul><li>+ (add) </li></ul></ul></ul><ul><ul><ul><li>- (subtract) </li></ul></ul></ul><ul><ul><ul><li>* (multiply) </li></ul></ul></ul><ul><ul><ul><li>/ (divide) </li></ul></ul></ul><ul><ul><ul><li>% (modulo) </li></ul></ul></ul>Binary Operators
10. 10. <ul><li>In the following set of statements: </li></ul><ul><ul><li>char ch; </li></ul></ul><ul><ul><li>ch=’S’; </li></ul></ul><ul><ul><li>ch=ch+’a’-‘A’; /*statement A*/ </li></ul></ul><ul><ul><li>ch=ch+’A’-‘a’; /*statement B*/ </li></ul></ul><ul><li>What will be the value of ch after: </li></ul><ul><ul><li>1. Statement A is executed? </li></ul></ul><ul><ul><li>2. Statement B is executed? </li></ul></ul>Practice: 2.3
11. 11. <ul><li>Solution: </li></ul><ul><ul><li>1. ch is equal to s . Note that ‘a’-‘A’ gives 32 after statement 1 is executed. </li></ul></ul><ul><ul><li>2. ch is back to S after statement 2 is executed. </li></ul></ul>Practice: 2.3 (Contd.)
12. 12. <ul><li>There are some set or rules, if followed, would prevent unexpected results, at the time of execution of programs: </li></ul><ul><ul><li>Any operand of type char is converted to int . </li></ul></ul><ul><ul><li>All floats are converted to doubles. </li></ul></ul><ul><ul><li>If either operand is double , the other is converted to a double , giving a double result. </li></ul></ul>Binary Operators (Contd.)
13. 13. <ul><li>In which of the following assignments is there no loss of data? ( i is an int , f a float , and d a double ) </li></ul><ul><ul><li>i=d; </li></ul></ul><ul><ul><li>d=f; </li></ul></ul><ul><ul><li>f=d; </li></ul></ul><ul><ul><li>i=f+d; </li></ul></ul><ul><ul><li>d=i+f; </li></ul></ul><ul><li>Is type casting necessary in the following example? </li></ul><ul><ul><li>int i,j; </li></ul></ul><ul><ul><li>float f; </li></ul></ul><ul><ul><li>double d; </li></ul></ul><ul><ul><li>d=f+(float) i + j ; </li></ul></ul>Practice: 2.4
14. 14. <ul><li>Solution: </li></ul><ul><ul><li>a. Loss of data. int set equal to a double. </li></ul></ul><ul><ul><li>b. No loss of data. double set equal to a float . c. Loss of data. float set equal to a double . d. Loss of data. Right-hand result is a double while left-hand side is just an int . e. No loss of data. Right-hand result is a double and left-hand side is also a double . </li></ul></ul><ul><ul><li>2. Not necessary. The ints will automatically be converted to doubles (following the conversion of the float to a double ). </li></ul></ul>Practice: 2.4 (Contd.)
15. 15. <ul><li>Ternary Operator: </li></ul><ul><ul><li>Is a shorthand method for writing if.else conditional construct. </li></ul></ul><ul><ul><li>Helps in reducing lines of code. </li></ul></ul><ul><ul><li>Has the following form for the expression using the ternary operator: </li></ul></ul><ul><ul><ul><li>(test-expression) ? T-expression : F-expression; </li></ul></ul></ul>Ternary Operator
16. 16. <ul><ul><li>Consider the following example: </li></ul></ul><ul><ul><ul><li>if(condition) </li></ul></ul></ul><ul><ul><ul><li>{ Statements if condition is true } </li></ul></ul></ul><ul><ul><ul><li>else </li></ul></ul></ul><ul><ul><ul><li>{ Statements if condition is false } </li></ul></ul></ul><ul><ul><li>Can be rewritten using the shorthand operator as follows: </li></ul></ul><ul><ul><li>larger_of_the_two = ( x > y ) ? x : y; </li></ul></ul>Ternary Operator (Contd.)
17. 17. <ul><li>1. State whether True or False: </li></ul><ul><ul><li>In the general form of an expression that uses a ternary operator, the test expression will be checked. If it is true, the T-expression will be evaluated, otherwise the F-expression will be evaluated. </li></ul></ul><ul><li>2. What will the following statement do? </li></ul><ul><ul><li>quotient = (b==0) ? 0 : (a/b); /*a, b, and quotient are ints*/ </li></ul></ul><ul><li>3. Can the preceding statement be written as follows? </li></ul><ul><ul><li>quotient = (b) ? (a/b) : 0; </li></ul></ul><ul><li>4. What will the following statement do? </li></ul><ul><ul><li>always_negative = (j>0) ? j : (-j); </li></ul></ul>Practice: 2.5
18. 18. <ul><li>Solution: </li></ul><ul><ul><li>True. </li></ul></ul><ul><ul><li>If b is non-zero, it will determine the quotient of a and b . If b equals zero, quotient is set to 0. </li></ul></ul><ul><ul><li>Yes. Note that if b is non-zero, the test expression ( b ) evaluates to true and hence quotient is set to ( a/b ). </li></ul></ul><ul><ul><li>The variable always_negative will always take on a non-negative value, i.e. it will be assigned the absolute value of j . The name of the variable always_negative is just a red herring. Remember that self-documenting variable names will help in writing programs that are readable. Note the unary operator ( -j ). </li></ul></ul>Practice: 2.5 (Contd.)
19. 19. <ul><li>Compound Assignment Operators: </li></ul><ul><ul><li>Are useful especially when long variable names are used. </li></ul></ul><ul><ul><li>Has the following general form: </li></ul></ul><ul><ul><li>left-value op= right-expression; </li></ul></ul><ul><ul><li>Here op can be either + (add), - (subtract, * (multiply), / (divide), and % (modulo). </li></ul></ul><ul><ul><li>Consider the following example: </li></ul></ul><ul><ul><ul><li>a_very_long_identifier=a_very_long_identifier + 2; </li></ul></ul></ul><ul><ul><li>It can be written as: </li></ul></ul><ul><ul><li>a_very_long_identifier += 2; </li></ul></ul>Compound Assignment Operators
20. 20. <ul><li>Increment / Decrement Operators: </li></ul><ul><ul><li>Are used to increase or decrease the value of a variable by 1. </li></ul></ul><ul><ul><li>Has the following two forms: </li></ul></ul><ul><ul><ul><li>The ++ (two plus symbols without a space), called the increment operator while that in ++ before the variable is called the pre increment operator and after the variable is called the post increment operator. </li></ul></ul></ul><ul><ul><ul><li>The -- (two minus symbols without a space), called the decrement operator while that in ++ before the variable is called the pre decrement operator and after the variable is called the post increment operator. </li></ul></ul></ul>Increment / Decrement Operators
21. 21. <ul><ul><li>Consider the following code snippet: </li></ul></ul><ul><ul><ul><li>total = sum++; /* statement A */ </li></ul></ul></ul><ul><ul><ul><li>total = ++sum; /* statement B */ </li></ul></ul></ul><ul><ul><ul><li>The first statement is equivalent to: </li></ul></ul></ul><ul><ul><ul><li>total = sum; sum = sum + 1; </li></ul></ul></ul><ul><ul><ul><li>While the second is the same as: </li></ul></ul></ul><ul><ul><ul><li>sum = sum + 1; total = sum; </li></ul></ul></ul>Increment / Decrement Operators (Contd.)
22. 22. <ul><li>Consider the following code snippet: </li></ul><ul><ul><li>int sum = 3, total = 5; </li></ul></ul><ul><ul><li>total = sum++; </li></ul></ul><ul><ul><li>total = ++sum; /*statement A */ </li></ul></ul><ul><ul><li>total = sum— </li></ul></ul><ul><ul><li>total = --sum; /*statement B */ </li></ul></ul><ul><li>What will be the values of total and sum after: </li></ul><ul><ul><li>statement A is executed? </li></ul></ul><ul><ul><li>statement B is executed? </li></ul></ul>Practice: 2.6
23. 23. <ul><li>State whether True or False: </li></ul><ul><ul><li>The following statement: </li></ul></ul><ul><ul><ul><li>for(i = 0; i< 100); i = i + 1) </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>Some statements </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li> can be written as: </li></ul></ul></ul><ul><ul><ul><li>for (i = 0; i < 100; i++) </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>Some statements </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>Practice: 2.6 (Contd.)
24. 24. <ul><li>State whether True or False: </li></ul><ul><ul><li>The for statement in #2 can also be written as: </li></ul></ul><ul><ul><ul><li>fori = 0; i < 100; ++i)/*Note: ++i and not i++*/ </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>Some statements </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><li>4. Write a program, which reads in a year and reports on whether it is a leap year or not (centuries should also be considered). </li></ul>Practice: 2.6 (Contd.)
25. 25. <ul><li>Solution: </li></ul><ul><ul><li>total=5, sum=5 </li></ul></ul><ul><ul><li>total=3, sum=3 </li></ul></ul><ul><ul><li>quite a complicated way of reducing total by 2. </li></ul></ul><ul><ul><li>2. True. i+1 is equivalent to i++. </li></ul></ul><ul><ul><li>True. i+1 is equivalent to 1+i. </li></ul></ul><ul><ul><li>4. </li></ul></ul>Practice: 2.6 (Contd.)
26. 26. <ul><li>The while and do…while looping constructs are generally used in situations where the number of execution of the loop is not known. </li></ul><ul><li>The for loop construct is used when the number of execution of the loop is known. </li></ul>Using Loops
27. 27. <ul><li>The for loop construct: </li></ul><ul><ul><li>Has three components in the loop control: </li></ul></ul><ul><ul><ul><li>Initialization </li></ul></ul></ul><ul><ul><ul><li>Condition </li></ul></ul></ul><ul><ul><ul><li>Re-initialization (increment/decrement)  </li></ul></ul></ul><ul><ul><li>Has the following sequence of execution: </li></ul></ul><ul><ul><ul><li>Initialization </li></ul></ul></ul><ul><ul><ul><li>Evaluation of loop condition </li></ul></ul></ul><ul><ul><ul><li>Body of loop </li></ul></ul></ul><ul><ul><ul><li>Re-initialization </li></ul></ul></ul>The for Loop Construct
28. 28. <ul><li>The sequence of execution of a complete for loop construct is shown in the following figure. </li></ul>The for Loop Construct (Contd.) TRUE INITIALIZATION EVALUATE CONDITION BODY OF LOOP REINITIALIZATION FALSE
29. 29. <ul><li>In a for loop construct: </li></ul><ul><ul><li>Multiple initializations and/or multiple re- initializations, are separated by commas. </li></ul></ul><ul><ul><li>Multiple conditions are specified using logical operators. </li></ul></ul><ul><li>  </li></ul>The for Loop Construct (Contd.)
30. 30. <ul><li>Write a function to accept twenty characters from the character set, and to display whether the number of lower-case characters is greater than, less than, or equal to number of upper-case characters. Display an error message if the input is not an alphabet. </li></ul><ul><li>Modify the function to accept characters endlessly until the character ! is input from keyboard. </li></ul>Practice: 2.7
31. 31. <ul><li>Solution: </li></ul><ul><li>1. </li></ul><ul><li>2. </li></ul>Practice: 2.7 (Contd.)
32. 32. <ul><li>At times there is a need to exit from a loop before the loop condition is re-evaluated after iteration. </li></ul><ul><li>To exit from loop control, break and continue statements are used. </li></ul>Controlling the Loop Execution
33. 33. <ul><li>Write a function, which accepts numbers until 0 is entered or 10 numbers have been accepted. The function prints the total number of entries, the number of positive entries, and the sum of all the positive numbers. </li></ul>Practice: 2.8
34. 34. <ul><li>Solution: </li></ul>Practice: 2.8 (Contd.)
35. 35. <ul><li>C provides the following functions for formatted input-output: </li></ul><ul><ul><li>printf() </li></ul></ul><ul><ul><li>scanf() </li></ul></ul>Using Formatted Input-Output Functions
36. 36. <ul><li>Syntax of the formatted output function printf() is: </li></ul><ul><li> printf (format, data1, data 2, ….); </li></ul><ul><li>Consider the following example: </li></ul><ul><li> printf(“%c”, inp); </li></ul><ul><li>The character specified after % is called a conversion character. </li></ul><ul><li>The conversion character allows one data type to be converted to another type and printed. </li></ul>Formatted Output
37. 37. <ul><li>The conversion characters and their meanings are shown in the following table. </li></ul>Formatted Output (Contd.) Character Meaning d the data is converted to decimal (integer) c the data is taken as a character s the data is a string and characters from the string are printed until a NULL character is reached f the data is output as a double or float with a default precision to 6
38. 38. <ul><li>What is the output of the statement: </li></ul><ul><ul><li>printf(“Integer is: %d; Alphabet is: %cn”, inum, inp); </li></ul></ul><ul><li>where inum contains 15 and inp contains Z . </li></ul>Practice: 2.9
39. 39. <ul><li>Solution: </li></ul><ul><ul><li>Integer is: 15; Alphabet is Z. </li></ul></ul>Practice: 2.9 (Contd.)
40. 40. <ul><li>The scanf() function is used for formatted input. </li></ul><ul><li>The syntax for the scanf() functions is as follows: </li></ul><ul><ul><li>scanf (format, data1, data2……); </li></ul></ul><ul><ul><li>Here </li></ul></ul><ul><ul><li>format - The format-specification string </li></ul></ul><ul><ul><li>data1, data2 - Data names where the input data is to be stored as per the format-specification string </li></ul></ul>Formatted Input
41. 41. <ul><li>The format-specification string in scanf() consists of: </li></ul><ul><ul><li>Blanks, tabs, (also called white space characters). </li></ul></ul><ul><ul><li>New line which are ignored. </li></ul></ul><ul><ul><li>Conversion consisting of %, an optional number specification specifying the width and a conversion character. </li></ul></ul><ul><li>While accepting strings using scanf() , a space is considered as a string terminator. </li></ul>Formatted Input (Contd.)
42. 42. Practice: 2.10 <ul><li>Write a function to accept and display the element number and the weight of a Proton. The element number is an integer and weight is fractional. </li></ul>
43. 43. Practice: 2.10 (Contd.) <ul><li>Solution: </li></ul><ul><ul><li>#include<stdio.h> </li></ul></ul><ul><ul><li>main() </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>int e_num; </li></ul></ul><ul><ul><li>float e_wt; </li></ul></ul><ul><ul><li>printf(“Enter the Element No. and Weight of a Protonn”); </li></ul></ul><ul><ul><li>scanf(“%d %f”, &e_num, &e_wt); </li></ul></ul><ul><ul><li>fflush(stdin); </li></ul></ul><ul><ul><li>printf(“The Element No. is: “, e_num); </li></ul></ul><ul><ul><li>printf(“The weight of a Proton is: %fn“, e_wt); </li></ul></ul><ul><ul><li>} </li></ul></ul>
44. 44. Practice: 2.11 <ul><li>Write a function to input a string of continuous characters with no white space as part of the input. The function should assign the input to variables of the types specified in the following table. </li></ul><ul><li>The function should also print out each of the assigned data items in separate lines. </li></ul>Position of character from start of string Number of characters Type of argument to assign 1 2 int 3 4 float 7 2 char (string) 9 3 int
45. 45. Practice: 2.11 <ul><li>Solution: </li></ul><ul><ul><li>#include<stdio.h> </li></ul></ul><ul><ul><li>main() </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>int i,j; </li></ul></ul><ul><ul><li>char str[3]; </li></ul></ul><ul><ul><li>float fnum; </li></ul></ul><ul><ul><li>printf(“Enter a string of 11 chrsn”); /*why 11: because 11 is the total length of */ /*input.*/ </li></ul></ul><ul><ul><li>scanf(“%2d %4f %2s %3d”,&i, &fnum, str, &j); </li></ul></ul><ul><ul><li>fflush(stdin); </li></ul></ul><ul><ul><li>printf(“%2dn %4fn %2sn %3dn”, i, fnum, str, j); </li></ul></ul><ul><ul><li>} </li></ul></ul>
46. 46. <ul><li>In this session, you learned that: </li></ul><ul><ul><li>An operator is a symbol that is used to command the computer to do mathematical or logical manipulations. </li></ul></ul><ul><ul><li>The operators in C language are classified into the following categories: </li></ul></ul><ul><ul><ul><li>Logical operators </li></ul></ul></ul><ul><ul><ul><li>Unary operators </li></ul></ul></ul><ul><ul><ul><li>Binary operators </li></ul></ul></ul><ul><ul><ul><li>Ternary operator </li></ul></ul></ul><ul><ul><ul><li>Compound assignment operators </li></ul></ul></ul><ul><ul><ul><li>Increment/Decrement operators </li></ul></ul></ul>Summary
47. 47. <ul><ul><li>The logical operators of C and their notations are as follows. </li></ul></ul><ul><ul><li>The unary operator prefixed to an integer constant or variable tells the compiler to reverse the sign by subtracting the value or variable from zero. </li></ul></ul><ul><ul><li>Binary operators in C language are + (add), - (subtract), * (multiply), / (divide), and % (modulo). </li></ul></ul><ul><ul><li>Ternary operator offers a shorthand way of writing the commonly used if…else construct. </li></ul></ul>Summary (Contd.) Operator Notation OR || AND && NOT !
48. 48. <ul><ul><li>The syntax for using the ternary operator is: </li></ul></ul><ul><ul><ul><li>(test-expression) ? T-expression : F-expression; </li></ul></ul></ul><ul><ul><li>Compound assignment operators simplify the statements. </li></ul></ul><ul><ul><li>Increment / Decrement operators are used to increment/decrement a variable by 1. </li></ul></ul><ul><ul><li>A for loop is used when the number of execution of the loop is known. </li></ul></ul><ul><ul><li>The components of a for loop construct are: </li></ul></ul><ul><ul><ul><li>initialization </li></ul></ul></ul><ul><ul><ul><li>loop condition </li></ul></ul></ul><ul><ul><ul><li>reinitialization (increment/decrement) </li></ul></ul></ul>Summary (Contd.)
49. 49. <ul><ul><li>The sequence of execution of a complete for loop is: </li></ul></ul><ul><ul><ul><li>initialization </li></ul></ul></ul><ul><ul><ul><li>evaluation of the loop condition </li></ul></ul></ul><ul><ul><ul><li>the body of the loop </li></ul></ul></ul><ul><ul><ul><li>reinitialization </li></ul></ul></ul><ul><ul><li>The break and continue statements are used to exit from loop control. </li></ul></ul><ul><ul><li>The break statement is used to exit from all loop constructs ( while , do...while , and for ) and switch...case statements. </li></ul></ul><ul><ul><li>The continue statement is used to skip all subsequent instructions and brings the control back to the loop. </li></ul></ul><ul><ul><li>The function printf() is used for formatted output to standard output based on a format specification. </li></ul></ul>Summary (Contd.)
50. 50. <ul><ul><li>The syntax of the function printf() is: </li></ul></ul><ul><ul><ul><li>printf(format, datal, data 2,,..); </li></ul></ul></ul><ul><ul><li>The function scanf() is used for formatted input from standard input and provides many of the conversion facilities of the function printf() . </li></ul></ul><ul><ul><li>The syntax of the function scanf() is: </li></ul></ul><ul><ul><ul><li>scanf (format, datal, data2, ...); </li></ul></ul></ul>Summary (Contd.)