Page 1 :
1, Programming for Problem Solving, (KCS-101), , (PART-II), , ➢ Use of Logical & Relational Operators: These operators are used in conditional operations as, follows:, 1. Logical AND (&&): In logical AND (&&) operation of two input statements, the output results as TRUE, (logic-1) only when both the statements are TRUE (logic-1) otherwise, the output results as FALSE (logic0)., 2. Logical OR (||): In logical OR ( || ) operation of two input statements, the output results as FALSE (logic0) only when both the statements are FALSE (logic-0) otherwise, the output results as TRUE (logic-1)., 3. Logical NOT (!): Logical NOT (!) can be operated on single input only. It reverses the result i.e. TRUE, to FALSE and vice-versa., NOTE: In C language, TRUE stands for Boolean value 1 and FALSE stands for Boolean value 0., E. g.:, , int x = 10, y = 5, z;, z = (x<5) && (y>10); //Result is false (F) hence z=0; because false is equivalent to 0, T, F, z = (x<5) || (y>10);, T, F, , //Result is true (T) hence z=1; because true is equivalent to 1, , Here is table for AND, OR and NOT operations:, X, Y, 0, 0, 0, 1, 1, 0, 1, 1, NOT (!) → reverse the bit, , X&&Y, 0, 0, 0, 1, , X||Y, 0, 1, 1, 1, , ➢ Use of Bitwise Operators: Bitwise operators are same as the logical operators but the operation is, performed bit by bit., Example: Let two binary sequences are given below as (10101010)2 and (11001101)2, Then the result of bitwise operators will be as below:, 1. Bitwise AND:, &, , 10101010, 11001101, 10001000, , 2. Bitwise OR:
Page 2 :
2, |, , 10101010, 11001101, 11101111, , NOTE: If we apply bitwise operators on two characters. Then the compiler computes 8 bit ASCII code, then applies bit by bit operation., e. g., , char ch1=’A’, ch2=’B’, ch;, ch=ch1&ch2;, , Then the result will be the result of ASCII value of A and ASCII value of B then convert both in 8 bit, binary code and compute bitwise AND (&) then resultant value is finally assigned to character ch., 3. Bitwise left shift (<<): This operator shifts bit sequence to the left, bit by bit, as required and inserts a, default 0 in empty position., e. g., , 101111<<1 will shift all bits one position to the left, hence, the result will be 011110, 101111<<2 will shift all bits two positions to the left, hence, the result will be 111100, Therefore, we can say in general:, 101111<<2 = 011110<<1 = 111100, 4. Bitwise right shift (>>): This operator shifts bit sequence to the right, bit by bit, as required and inserts, a default 0 in empty position., e. g., , 101111>>1 shifts all the bits one position to the right, hence, the result will be 010111, 101111>>2 shifts all the bits two positions to the right, hence, the result will be 001011, Therefore, we can say in general:, 101111>>2 = 010111<<1 = 001011, , ➢ Assignment operators ( =, +=, -=, *=, /= etc.): In assignment operation, the object value, of right hand side variables are copied into address of left hand side variable., i. e., , a = 10;, b = a;, Here, 10 is copied into address of b which means now b is equal to 10., NOTE: The assignment a=a+1; is equivalent to a+=1; and so on., , ➢ Increment and decrement operators (++ and --): There are two methods for increment, and decrement operators; Prefix and postfix., , 1. Pre-fix Notation: In prefix notation, first increment or decrement occurs then the operation, takes place., Syntax:, , ++x, --y etc., , 2. Post-fix Notation: In postfix notation, first operation is performed then increment or decrement, takes place., Syntax:, NOTE THAT:, , x++, y-- etc., a++; is equivalent to, , a=a+1;
Page 3 :
3, Similarly,, , a--;, , is equivalent to, , a=a-1;, , For example: a = 10;, b = ++a;, In this case, prefix notation first increases the value of a by one and then assigns it to b., Thus, the value of a and b both are same i.e. 11., Now, consider postfix notation:, a=10;, b=a++;, Here, first, the value of a is assigned to b and then the value of a increases by one., Thus, the values of a and b are 11 and 10 respectively., , ➢ Conditional operator (? :) :, Conditional operator is also known as ternary operator, since its syntax divided in three parts., i. e., , expression1 ? expression2 : expresion3, Condition test, , T, , F, , It means if expression1 is true then return expression2 otherwise expresion3., Let, , a=100;, b=50;, x = (a>b) ? a : b;, , Here, it will return x = 100., , ➢ Comma operator ( , ):, Comma operator is used to link operators together. The expression gets evaluated from left to right, and the rightmost expression is the result., For example: Expression X = (a = 10, b = 20, a + b); will return 30 to X i. e. X = 30., , Module – 3
Page 4 :
4, (*Conditions, Loops & Functions), Control Instructions in C: As the name suggests the ‘control instructions’ enable us to specify the, order in which the various instructions in a program are to be executed by the computer. In other words, the, control instructions determine the ‘flow of control’ in a program. There are 3 types of control instructions in C:, (a) Sequence Control Instructions, (b) Selection or Decision (Condition) & Case Control Instructions, (c) Repetition or Loop Control Instructions, , (a) Sequence Control Instructions: The Sequence control instruction ensures that the instructions, are executed in the same order in which they appear in the program. By default the instructions in a program are, executed sequentially. (Refer to class notes for example programs)., , (b) Selection or Decision Control Instructions: Many a times, we want a set of instructions to, be executed in one situation, and an entirely different set of instructions to be executed in another situation. This, kind of situation is dealt in C programs using a decision control instruction. A decision control instruction can be, implemented in C using:, ➢ if statement, ➢ if-else statement, ➢ switch case default statements, , ➢ if Statement:, , C uses the keyword if to implement the decision control instruction. In if method any, condition can be tested whether by single relational operation or by an expression. When the condition meets, TRUE then body of if will get executed, otherwise body of if will be skipped and control goes to remaining, statements of main body., The general form of if statement looks like this:, if ( this condition is true ), execute this statement ;, , The keyword ‘if’ tells the compiler that the condition following the keyword if (always enclosed within a pair of, parentheses) is a decision control instruction. If the condition, whatever it is, is TRUE, then the statement is, executed. If the condition is not true then the statement is not executed., //Demo of if condition, void main(), {, int a=10,b=20;, if(a<100), {, printf(“ a is =%d\t”,a);, }, printf(“b is =%d”,b);, }, Output: a is = 10, , b is = 20, , //execute both statements because if body is TRUE.
Page 5 :
5, void main(), {, int a=10,b=20;, if(a>100), {, printf(“ a is =%d\t”,a);, }, printf(“b is =%d”,b);, }, Output: b is 20, , //because if body will not execute due to FALSE condition., , NOTE: In nested if situations, ‘if’ condition can be given inside if at any level., , ➢ if else Statements: In if statement only TRUE condition considered but in if else statement FALSE, condition of if statement goes to else statement as alternate., Syntax:, , if (test condition), {, Statements; // execute when ‘if’ condition meets TRUE, }, else, {, Statements; //execute when ‘if’ condition meets FALSE, }, Example of leap year problem: WAP in C to check whether the given year is leap or not., Logic for Solution: Any year is called “leap year” if it is completely divisible by 4 i.e. remainder becomes zero., //Program to check given year is leap or not, void main(), {, int year;, printf(“ENTER THE YEAR:\n”);, scanf(“%d”,&year);, if (year%4==0), {, printf(“\n LEAP YEAR”);, }, else, {, printf(“\n NOT LEAP YEAR”);, }, }, Output (1st Run):, ENTER THE YEAR: 2003, NOT LEAP YEAR, Output (2nd Run):, , //because condition meets FALSE and else body executed
Page 6 :
6, ENTER THE YEAR: 2008, LEAP YEAR, , //because condition meets TRUE and if body executed, , NOTE: In nested if else, the if and else statements can be given inside if and else body at any level., , ➢ Various Forms of if: The if statement can take any of the following forms:, •, •, , •, , •, , •, , •, , if ( condition ), do this ;, if ( condition ), {, do this ;, and this ;, }, if ( condition ), do this ;, else, do this ;, if ( condition ), {, do this ;, and this ;, }, else, {, do this ;, and this ;, }, if ( condition ), do this ;, else, {, if ( condition ), do this ;, else, {, do this ;, and this ;, }, }, if ( condition ), {
Page 7 :
7, if ( condition ), do this ;, else, {, do this ;, and this ;, }, }, else, do this ;, NOTE: For example programs, do refer to your class notes., , Disadvantages of if statements: As we see, in if statements there are number of alternatives. If we need, one alternative at a time, we would require more and more if statements. Hence the complexity will increase with, number of alternatives. switch case statements avoid this type of problem., , ➢ switch case default Statements: The control statement that allows us to make a decision from, the number of choices is called a switch, or more correctly a switch-case-default, since these three, keywords go together to make up the control statement., Syntax of switch:, switch (expression), {, case constant1:, statement1;, break;, case constant2:, statement2;, break;, :, :, :, case constantN:, statementN;, break;, default:, default statement;, }, Where constant1……….constantN are results of expression tested. Only one statement (or set of statements) out, of statement1……….statementN will execute because expression returns only one result at a time. Hence it, requires break after every case statement. If result will not match any case then control will be transferred to, default body and then back in main body., IMPORTANT NOTE:
Page 8 :
8, 1. The limitation of switch statement is that, in switch, we can use only integer, character or any, expression which output either character or integer value., 2. The character case must be given into single quotation mark (i.e. ‘A’)., 3. Each constant in each case must be different from all the others., 4. We can execute more than one case into single case as given below:, case ‘A’:, case ‘a’:, Consider the following program:, /*Demonstration of switch-case-default*/, void main( ), {, int i = 2 ;, clrscr();, switch ( i ), {, case 1 :, printf ( "I am in case 1 \n" ) ;, break ;, case 2 :, printf ( "I am in case 2 \n" ) ;, break ;, case 3 :, printf ( "I am in case 3 \n" ) ;, break ;, default :, printf ( "I am in default \n" ) ;, }, getch();, }, The output of this program would be:, I am in case 2, , Use of break & default in switch case statements:, ➢ C uses the keyword break to terminate the current execution and send control to outside executing case, body whereas keyword default is used to control if there are unmatched cases of switch expression., ➢ In switch structure, break & default are optional statements but required to improve the programming, efficiency., a. If break is not used then control executes all cases until last break statement will meet or, encounters end of switch., b. If unmatched case is found then control executes default section and then terminate. default can, be used anywhere in control body but only once., , ❖ Tips and Traps (switch statement):, A few useful tips about the usage of switch and a few pitfalls to be avoided:, a) The earlier program that used switch may give you the wrong impression that you can use only, cases arranged in ascending order, 1, 2, 3 and default. You can in fact put the cases in any order, you please. Here is an example of scrambled case order:
Page 9 :
9, void main( ), {, int i = 22 ;, switch ( i ), {, case 121 :, printf ( "I am in case 121 \n" ) ;, break ;, case 7 :, printf ( "I am in case 7 \n" ) ;, break ;, case 22 :, printf ( "I am in case 22 \n" ) ;, break ;, default :, printf ( "I am in default \n" ) ;, }, getch();, }, The output of this program would be:, I am in case 22, b) You are also allowed to use char values in case and switch as shown in the following program:, void main( ), {, char c = 'x' ;, clrscr();, switch ( c ), {, case 'v' :, printf ( "I am in case v \n" ) ;, break ;, case 'a' :, printf ( "I am in case a \n" ) ;, break ;, case 'x' :, printf ( "I am in case x \n" ) ;, break ;, default :, printf ( "I am in default \n" ) ;, }, getch();, }, The output of this program would be: I am in case x, In fact here when we used ‘v’, ‘a’, ‘x’ they are actually replaced by the ASCII values (118, 97, 120) of these, character constants., c) At times we may want to execute a common set of statements for multiple cases. How this can be, done is shown in the program example of “Mathematical Calculator”., d) Even if there are multiple statements to be executed in each case there is no need to enclose them, within a pair of braces (unlike if, and else).
Page 10 :
10, e) Every statement in a switch must belong to some case or the other. If a statement doesn’t belong, to any case the compiler won’t report an error. However, the statement would never get executed., For example, in the following program the printf( ) never goes to work., void main( ), {, int i, j ;, clrscr();, printf ( "Enter value of i" ) ;, scanf ( "%d”, &i ) ;, switch ( i ), {, printf ( "Hello" ) ;, case 1 :, j = 10 ;, break ;, case 2 :, j = 20 ;, break ;, }, getch();, }, f) If we have no default case, then the program simply falls through the entire switch and continues, with the next instruction (if any,) that follows the closing brace of switch., g) Is switch a replacement for if? Yes and no. Yes, because it offers a better way of writing programs, as compared to if, and no because in certain situations we are left with no choice but to use if. The, disadvantage of switch is that one cannot have a case in a switch which looks like: case i <= 20 : All, that we can have after the case is an int constant or a char constant or an expression that evaluates, to one of these constants. Even a float is not allowed. The advantage of switch over if is that it leads, to a more structured program and the level of indentation is manageable, more so if there are, multiple statements within each case of a switch., h) We can check the value of any expression in a switch. Thus the following switch statements are legal., switch ( i + j * k ), switch ( 23 + 45 % 4 * k ), switch ( a < 4 && b > 7 ), Expressions can also be used in cases provided they are constant expressions (Cases can never have, variable expressions). Thus case 3+7: is correct, however, case a+b: or case a+3: is incorrect., i) A float expression cannot be tested using a switch., j) Multiple cases cannot use same expressions. Thus the following switch is illegal:, switch ( a ), {, case 3 :, ..., case 1 + 2 :, ..., }, Example: WAP in C for mathematical calculator for addition & subtraction operations., Answer:, /*Program for Mathematical Calculator*/, void main(), {
Page 11 :
11, int x=50,y=20,z;, char ch;, clrscr();, printf ("\n ENTER A FOR ADDITION");, printf ("\n ENTER S FOR SUBTRACTION");, printf ("\n ENTER YOUR CHOICE\t");, scanf ("%c",&ch);, switch (ch), //switch character value given through keyboard, {, case 'A':, case ‘a’:, case ‘+’:, z=x+y;, printf("\nAddition of x and y is = %d",z);, break;, case 'S':, case ‘s’:, case ‘-’:, z=x-y;, printf("\nSubtraction of x and y is =%d",z);, break;, default:, printf("\n ENTER CORRECT CHOICE");, break;, }, getch();, }, The output will be as shown below:, ENTER A FOR ADITION, ENTER S FOR SUBTRACTION, ENTER YOUR CHOICE A, Addition of x and y is =70, //Here value of ch is A hence case ‘A’ will executed., , Advantages & Disadvantages of switch over if:, Is switch a replacement for if? Yes and no. Yes, because it offers a better way of writing programs as, compared to if, and no because in certain situations we are left with no choice but to use if., The disadvantage of switch is that one cannot have a case in a switch which looks like:, case i <= 20 :, All that we can have after the case is an int constant or a char constant or an expression that evaluates, to one of these constants. Even a float is not allowed., The advantage of switch over if is that it leads to a more structured programming and the level of, indentation is manageable, more so if there are multiple statements within each case of a switch., , ➢ Repetition or Loop Control Instructions: The versatility of the computer lies in its ability, to perform a set of instructions repeatedly. This involves repeating some portion of the program either a, specified number of times or until a particular condition is being satisfied. This is done through a loop
Page 12 :
12, control instruction. The loop control instruction helps computer to execute a group of statements, repeatedly., , The Loop Control Structure:, Loops are used to execute any statements more than one times as required. It is better to write any, statement in loop body than write statement more than one times. There are two methods used in loop structures:, i.e. entry control loop and exit control loop., , 1. Entry Control Loop: In entry control loops, the condition is checked first (and is TRUE) then statements, associated to it get executed until condition turns FALSE., , 2. Exit Control Loop: In exit control loops, irrespective of the condition, the associated statements get, executed first then the condition is checked; now:, i., If it is TRUE, execution continues until condition becomes FALSE., ii., If it is FALSE, the execution terminates immediately., It means in case ii, loop will execute at least once even if condition is FALSE., , ❖ C provides three looping constructs by way of which we can repeat a part of a program. They are:, ➢ Using a while loop, ➢ Using a do-while loop, ➢ Using a for loop, Here we will learn syntax and examples of each constructs in all loops there are three sections:, (i), Initialization, (ii), Test condition, (iii), Increment / decrement, All these sections can have either integer or floating point values (depending on the programmer)., , ➢ while loop: In while loop, initial condition is given before the loop body followed by condition test in, loop and increment or decrement occurs inside the loop body., The syntax is shown below:, , Initialization;, while (test-condition), {, Statements;, Increment or decrement;, }, Example:, , /*Program to print Kashi IT five times using while loop*/, main(), {, int i;, i=0;, while (i<5), {, printf(“ Kashi IT \n”);
Page 13 :
13, i++;, }, getch();, }, The output will be:, Kashi IT, Kashi IT, Kashi IT, Kashi IT, Kashi IT, , Tips and Traps (while loop):, a. The statements within the while loop would keep on getting executed till the condition being tested, remains true. When the condition becomes false, the control passes to the first statement that follows the, body of the while loop., b. In place of the condition there can be any other valid expression. So long as the expression evaluates to a, non-zero value the statements within the loop would get executed., c. The condition being tested may use relational or logical operators as shown in the following examples:, while ( i <= 10 ), while ( i >= 10 && j <= 15 ), while ( j > 10 && ( b < 15 || c < 20 ) ), d. The statements within the loop may be a single line or a block of statements. In the first case the, parentheses are optional. For example:, while ( i <= 10 ), i = i + 1;, is same as, while ( i <= 10), {, i = i + 1;, }, e. As a rule the while must test a condition that will eventually become false, otherwise the loop would be, executed forever, indefinitely., main( ), {, int i = 1 ;, while (i <= 10 ), printf(“ %d\n", i ) ;, }, This is an indefinite loop, since i remain equal to 1 forever., The correct form would be as given under:, main( ), {, int i = 1 ;
Page 14 :
14, while (i <= 10 ), {, printf(“ %d\n", i ) ;, i=i + 1;, }, f. Instead of incrementing the loop counter, we can even decrement it., main( ), {, int i = 10 ;, while (i >= 1 ), {, printf(“ %d\n", i ) ;, i=i - 1;, }, g. It is not necessary that a loop counter must only be an int. It can even be a float., main( ), {, float x=10.0 ;, while (x <= 10.5 ), {, printf(“ %f\n", x ) ;, x=x + 0.1;, }, h. Even floating point loop counters can be incremented or decremented. Once again the increment and, decrement could be by any value, not necessarily 1., i. += is a compound assignment operator. Hence, i = i + 10 can also be written as i += 10., Other compound assignment operators are -=, *=, / = and %=., j. Consider the following program segments:, /*Demo of post-increment operator*/, main( ), {, int i = 0 ;, while (i++ < 10), {, printf(“ %d\n", i ) ;, }, In the statement while (i++ <= 10), firstly the comparison of value of i with 10 is performed, and then the, increment of i takes place. Since the increment of i happens after its usage, here the ++ operator is called a postincrement operator., In the above program, when the control reaches printf( ), the value of i has already been incremented., /*Demo of pre-increment operator*/, main( ), {
Page 15 :
15, int i = 0 ;, while (++i < 10), {, printf(“ %d\n", i ) ;, }, In the statement while (++i <= 10), firstly increment of i takes place, then the comparison of value of i, with 10 is performed. Since the increment of i happens before its usage, here the ++ operator is called a preincrement operator., , ➢ for loop: The, , for loop allows us to specify three things about a loop in a single line; i.e., 1. Setting a loop counter to an initial value., 2. Testing the loop counter to determine whether its value has reached the number of repetitions, desired., 3. Increasing the value of loop counter each time the program segment within the loop has been, executed., , All the above three sections are separated by (;) as shown in syntax below:, , for (initialization; test condition; increment or decrement), {, statements;, }, Example:, , /*Program to print Kashi IT five times using for loop*/, main(), {, int i;, for (i=1; i<=5; i++), {, printf (“ Kashi IT \n”);, }, }, , The output will be:, Kashi IT, Kashi IT, Kashi IT, Kashi IT, Kashi IT, NOTE: We can give any initial value as well as decrement or increment values as per requirement., For example, above loop is similar to:, for (i=9; i>=0; i--), , Nesting of Loops: The way if statements can be nested, similarly whiles and fors can also be nested., To understand how nested loops work; look at the program given below:
Page 16 :
16, /* Demonstration of nested loops */, void main( ), {, int r, c, sum;, for ( r = 1 ; r <= 3 ; r++ ) /* outer loop */, {, for ( c = 1 ; c <= 2 ; c++ ) /* inner loop */, {, sum = r + c ;, printf ( "r = %d c = %d sum = %d\n", r, c, sum ) ;, }, }, getch();, }, When you run this program you will get the following output:, r = 1 c = 1 sum = 2, r = 1 c = 2 sum = 3, r = 2 c = 1 sum = 3, r = 2 c = 2 sum = 4, r = 3 c = 1 sum = 4, r = 3 c = 2 sum = 5, Explanation: Here, for each value of r the inner loop is cycled through twice, with the variable c taking values, from 1 to 2. The inner loop terminates when the value of c exceeds 2, and the outer loop terminates when the, value of r exceeds 3., Instead of using two statements, one to calculate sum and another to print it out, we can compact this into one, single statement by saying:, printf ( "r = %d \t c = %d sum = %d\n", r, c, r + c ) ;, NOTE: The way for loops have been nested here, similarly, two while loops can also be nested. Not only this,, a for loop can occur within a while loop, or a while within a for., , ➢ do while loop:, , There is a minor difference between the working of while and do while loops. This, difference is the place where the condition is tested. The while tests the condition before executing any of the, statements within the while loop. As against this, the do while tests the condition after having executed the, statements within the loop. The syntax is as given below., , Initialization;, do, {, Statements:, }, while (test condition); //(;) is necessary at last., /*Program to print Kashi IT five times using do while loop*/, main(), {
Page 17 :
17, int i;, i=0;, do, {, printf(“ Kashi IT \n”);, i++;, }, while(i<10);, }, Output: print Kashi IT five times., , •, •, , For infinite loops; user can control by explicit method using own concept., In for loop, the following statement will execute infinite time., for ( ; ; ), For other loops; infinite execution gives a condition which will never meet. Such as:, int i=1;, while(i>0), {, printf(“Kashi IT\n”);, i++;, }, //Print infinite times because i always greater than 0, , IMPORTANT NOTE: Programmers should always avoid this type of condition., , The break Statement:, We often come across situations where we want to jump out of a loop instantly, without waiting to get, back to the conditional test. The keyword break allows us to do this. When break is encountered inside any loop,, control automatically passes to the first statement after the loop. i. e. break statement terminates the loop at any, specific condition. A break is usually associated with an if. As an example, let’s consider the following example:, main(), {, int i;, for(i=0;i<10;i++), {, printf(“ %d\t ”,i);, if(i==5), break;, }, }, Output: Print numbers from 0 to 5 and halt when i==5, i.e., 0, 1, 2, 3, 4, 5, Example 2: Write a program in C to determine whether a number is prime or not., , •, , Logic: A prime number is one, which is divisible only by 1 or itself.
Page 18 :
18, All we have to do to test whether a number is prime or not, is to divide it successively by all numbers, from 2 to one less than itself. If remainder of any of these divisions is zero, the number is not a prime. If no, division yields a zero then the number is a prime number. Following program implements this logic., main( ), {, int num, i ;, printf ( "Enter an integer number " ) ;, scanf ( "%d", &num ) ;, i=2;, while ( i <= num - 1 ), {, if ( num % i == 0 ), {, printf ( "Not a prime number" ) ;, break ;, }, i++ ;, }, if ( i == num ), printf ( "Prime number" ) ;, }, In this program the moment num % i turns out to be zero, (i.e. num is exactly divisible by i) the message, “Not a prime number” is printed and the control breaks out of the while loop. Why does the program require, the if statement after the while loop at all? Well, there are two ways the control could have reached outside the, while loop:, a. It jumped out because the number proved to be not a prime., b. The loop came to an end because the value of i became equal to num., When the loop terminates in the case b, it means that there was no number between 2 to num - 1 that, could exactly divide num. i.e, num is indeed a prime. If this is true, the program should print out the message, “Prime number”., Note that the keyword break, breaks the control only from the while in which it is placed., Consider the following program, which illustrates this fact., main( ), {, int i = 1 , j = 1 ;, while ( i++ <= 100 ), {, while ( j++ <= 200 ), {, if ( j == 150 ), break ;, else, printf ( "%d %d\n", i, j ) ;, }, }, }
Page 19 :
19, In this program when j equals 150, break takes the control outside the inner while only, since it is placed, inside the inner while., , The continue Statement:, In some programming situations we want to take the control to the beginning of the loop, bypassing the, statements inside the loop, which have not yet been executed. The keyword continue allows us to do this. When, continue is encountered inside any loop, control automatically passes to the beginning of the loop., NOTE: continue statement avoids only the condition tested and remain continue the execution., For example:, main(), {, int i;, for(i=0;i<10;i++), {, if(i==5), continue;, printf(“ %d\t ”,i);, }, }, Output:, , 0, , 1, , 2, , 3, , 4, , 6, , 7, , 8, , 9, , i.e. print numbers 0 to 9 except 5 since continue use to skip any statement such as skip 5 in above program., ▪, , A continue is usually associated with an if. As an example, let's consider the following program., main( ), {, int i, j ;, for ( i = 1 ; i <= 2 ; i++ ), {, for ( j = 1 ; j <= 2 ; j++ ), {, if ( i == j ), continue ;, printf ( "\n%d\t %d\n", i, j ) ;, }, }, }, The output of the above program would be..., 1, 2, , 2, 1, , NOTE: Refer to class notes for more programming examples., ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~