Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

C Programming 4

Uploaded by

laihoptuan2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

C Programming 4

Uploaded by

laihoptuan2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

C Programming

Lecture 4: Loop Control ⟲

1 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 2 / 50
An opening example
• Calculate S = 5x=1 x12
P

• Based on what we learn, we do it in following way


1 i n t main ( )
2 {
3 int x = 1;
4 double S = 0;
5 S += 1 . 0 / ( x ∗ x ) ;
6 x += 1 ;
7 S += 1 . 0 / ( x ∗ x ) ; • It is okay when the number
8 x += 1 ;
9 S += 1 . 0 / ( x ∗ x ) ; of terms is small
10 x += 1 ; • How about 1000 terms ...
11 S += 1 . 0 / ( x ∗ x ) ;
12 x += 1 ; • Share the story
13 S += 1 . 0 / ( x ∗ x ) ;
14 p r i n t f ( ”S = % l f \n” , S ) ;
15 return 0;
16 }

C Programming 3 / 50
Motivation of loops

• In the above example


• Following statement repeated for 5 times, only x changes each time
1 x += 1 ;
2 S += 1 . 0 / ( x ∗ x ) ;

• We can put it inside a loop


• Tell the loop that how many times we want to repeat
1 x = 0;
2 w h i l e ( x <= 4 )
3 {
4 x += 1 ;
5 S += 1 . 0 / ( x ∗ x ) ;
6 }

C Programming 4 / 50
Loops
• To repeat statements as long as a certain condition is true (non-zero)
• C offers 3 different loops
• We can replace one with another
• Different loop offers different convenience
while ( condition )
statement ;

do
statement ;
while ( condition ) ;

f o r ( i n i t i a l i z a t i o n ; condition ; statement )
statement ;

For multiple statements again, use braces.


C Programming 5 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 6 / 50
while loop control (1)

• The execution checks if the condition is still non-zero


• If it is, execute the statement(s)
• Otherwise, gets out from the loop

zero
condition
non-zero

statement(s)

C Programming 7 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
while loop control (2)
• The execution of checks if the condition is still non-zero
• If it is, execute the statement(s)
• Otherwise, gets out from the loop

1 int i = 2;
2 w h i l e ( i > 0)
3 −− i ;
4 p r i n t f ( ” done \n” ) ;

1 Check (i > 0) → true → go to line 3


2 Decrement i → i now is 1, go back to line 2
3 Check (i > 0) → true → go to line 3
4 Decrement i → i now is 0, go back to line 2
5 Check (i > 0) → false → go to line 4
6 Print done
C Programming 8 / 50
Check Prime Number (1)

• Check whether an integer number if a prime number


• Prime number: number that is only dividable by 1 and itself
• 81 is not a prime number; 173 is prime number
• Any idea to solve this problem??

5 minutes to think about this problem ...

C Programming 9 / 50
Check Prime Number (2)
1 Start from 2 to N
2 Check whether N is dividable by any number in this range
1 i n t i = 2 , N = 177;
2 i n t PRIME = 1 ;
3 w h i l e ( i < N)
4 {
5 i f (N%i == 0 )
6 {
7 PRIME = 0 ;
8 }
9 }
10 i f ( PRIME )
11 p r i n t f ( ”%d i s a p r i m e number \n” , N) ;
12 else
13 p r i n t f ( ”%d i s n o t a p r i m e number \n” , N) ;

• Do we miss anything?

C Programming 10 / 50
Check Prime Number (3)
1 Start from 2 to N
2 Check whether N is dividable by any number in this range

1 i n t i = 2 , N = 177;
2 i n t PRIME = 1 ;
3 w h i l e ( i < N)
4 {
5 i f (N%i == 0 )
6 {
7 PRIME = 0 ;
8 }
9 i ++;
10 }
11 i f ( PRIME )
12 p r i n t f ( ”%d i s a p r i m e number \n” , N) ;
13 else
14 p r i n t f ( ”%d i s n o t a p r i m e number \n” , N) ;

C Programming 11 / 50
Check Prime Number (4)
1 In the above example, we no need to √all the numbers in [2· · · N-1]
2 N is not dividable by numbers after ⌈ N⌉
1 #i n c l u d e < s t d i o . h>
2 #i n c l u d e <math . h>
3 i n t main ( )
4 {
5 i n t i = 2 , N = 177;
6 i n t PRIME = 1 , bnd = ( i n t ) c e i l ( s q r t (N) ) ;
7 w h i l e ( i <= bnd )
8 {
9 i f (N%i == 0 )
10 {
11 PRIME = 0 ;
12 }
13 i ++;
14 }
15 i f ( PRIME )
16 p r i n t f ( ”%d i s a p r i m e number \n” , N) ;
17 else
18 p r i n t f ( ”%d i s n o t a p r i m e number \n” , N) ;
19 return 0;
20 }

C Programming 12 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 13 / 50
do...while (1)

• do...while executes the statement(s) first


• Checks the condition after each run

1 int i = 3; 1 int i = 3;
2 do 2 w h i l e ( i > 1)
3 { 3 {
4 −− i ; 4 −− i ;
5 p r i n t f ( ” i=%d\n” , i ) ; 5 p r i n t f ( ” i=%d\n” , i ) ;
6 } w h i l e ( i > 1) ; 6 }

• What is the output??

C Programming 14 / 50
do...while (2)

• do...while executes the statement(s) first


• Checks the condition after each run

1 i =2 1 i =2
2 i =1 2 i =1

• What is the output??

C Programming 15 / 50
do...while (3)

• do...while executes the statement(s) first


• Checks the condition after each run

statement(s)

non-zero
condition
zero

C Programming 16 / 50
Example 1 (1)


• Calculate x = a
• xn+1 = 21 (xn + xa )
n
• Loop until error less than 10−5 in consecutive iterations
• Hints: x1 is an arbitrary positive value

3 minutes to think about this problem ...

C Programming 17 / 50
Example 1 (2)


• Calculate x = a
• xn+1 = 21 (xn + xa )
n
• Loop until error less than 10−5 in consecutive iterations
• Hints: x1 is an arbitrary positive value
1 We need a loop (while? do-while or for?)
2 We need to keep two results from consecutive iterations
3 Anything else??
4 Let’s do it!

C Programming 18 / 50
Example 1 (3)

• Calculate x = a
• xn+1 = 21 (xn + xa )
n
• Loop until error less than 10−5 in consecutive iterations
• Hints: x1 is an arbitrary positive value

1 f l o a t a = 5 , x0 = 3 . 1 , xn = 0 , e r r = 0 ;
2 do
3 {
4 xn = 0 . 5 ∗ ( xn+a / xn ) ;
5 e r r = a b s ( xn − x0 ) ;
6 } w h i l e ( e r r >= 0 . 0 0 0 0 1 )
7 p r i n t f ( ” s q r t ( a )=%f \n” , xn ) ;

• Anything wrong??

C Programming 19 / 50
Example 1 (4)

• Calculate x = a
• xn+1 = 21 (xn + xa )
n
• Loop until error less than 10−5 in consecutive iterations
• Hints: x1 is an arbitrary positive value
1 f l o a t a = 5 , xk = 0 , xn = 3 . 1 , e r r = 0 ;
2 int i = 0;
3 do
4 {
5 xk = xn ;
6 xn = 0 . 5 ∗ ( xk+a / xk ) ;
7 // p r i n t f (”% f \ t%f \ t%f \n ” , xk , xn , e r r ) ;
8 e r r = f a b s ( xn − xk ) ;
9 i ++;
10 } w h i l e ( e r r >= 0 . 0 0 0 0 1 ) ;
11 p r i n t f ( ” i t e r s = %d , s q r t ( a )=%f \n” , i , xn ) ;

• Use “fabs(.)” instead of “abs(.)”


C Programming 20 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 21 / 50
for loop (1)
The For-Loop is comfortable for iterating. It takes three arguments.
• Initialization (i=0;)
• Condition (i < 5;)
• Iteration statement (i+=1)

START

initialize i = 0;

test i < 5;

body of loop

increment i++

C Programming 22 / 50
for loop (2)

• Consider a program printing the numbers 1 to 10:

int i ;
f o r ( i = 1 ; i <= 1 0 ; ++i )
{
p r i n t f ( ”%d\n” , i ) ;
}

• i starts from 1
• Check if i is less than or equal to 10
• Go into the loop if it is true (non-zeor)
• Increment i, e.g., i++ or i+=2

C Programming 23 / 50
break

• Similar as switch-case
• break can be used inside a loop
• Jumping out from the loop as soon as it is called

int i , s = 0;
f o r ( i = 1 ; i <= 1 0 ; ++i )
{
s += 2∗ i ;
i f ( i %4 == 0 )
break ;
}
p r i n t f ( ” s=%d\n” , s ) ;

C Programming 24 / 50
continue

• Different from break


• continue can be ONLY used inside a loop
• Ingore statements followed, go to next round of loop

1 int i , s = 0; 1 int i , s = 0;
2 f o r ( i = 1 ; i <= 1 0 ; ++i ) 2 f o r ( i = 1 ; i <= 1 0 ; ++i )
3 { 3 {
4 s += 2∗ i ; 4 s += 2∗ i ;
5 i f ( i %4 == 0 ) 5 i f ( i %4 == 0 )
6 break ; 6 continue ;
7 } 7 }
8 p r i n t f ( ” s=%d\n” , s ) ; 8 p r i n t f ( ” s=%d\n” , s ) ;

C Programming 25 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 26 / 50
Example 2 (1)

• Given following series of fraction


• 21 , 32 , 35 , 85 , 13 21
8 , 13 ,· · ·
• Work out the sum of first 20 terms

3 minutes to think about this problem ...

C Programming 27 / 50
Example 2 (2)

• Given following series of fraction


• 21 , 32 , 35 , 85 , 13 21
8 , 13 ,· · ·
• Work out the sum of first 20 terms
• We observe that numerator is the sum of the numerators of last two
• The denominator is the sum of the denominators of last two
• We have following things first

1 f l o a t n1 = 2 , n2 = 3 ;
2 i n t d1 = 1 , d2 = 2 ;
3 f o r ( i = ? ; i <= 2 0 ; ++i )
4 {
5 ....
6 }

C Programming 28 / 50
Example 2 (3)

• Given following series of fraction


• 21 , 32 , 35 , 85 , 13 21
8 , 13 ,· · ·
• Work out the sum of first 20 terms
• We need the variable to keep the result
• We need an iterator

1 f l o a t n1 = 2 , n2 = 3 ;
2 i n t d1 = 1 , d2 = 2 , i = 0 ;
3 f l o a t s = n1 / d1 + n2 / d2 ;
4 f o r ( i = ? ; i <= 2 0 ; ++i )
5 {
6 ....
7 }
8 p r i n t f ( ” s=%f \n” , s ) ;

C Programming 29 / 50
Example 2 (4)
• Given following series of fraction
• 21 , 32 , 35 , 85 , 13 21
8 , 13 ,· · ·
• Work out the sum of first 20 terms
• We need an iterator, start from where??
• How to work out n1 and d1

1 f l o a t n1 = 2 , n2 = 3 ;
2 i n t d1 = 1 , d2 = 2 , i = 0 ;
3 f l o a t s = n1 / d1 + n2 / d2 ;
4 f o r ( i = ? ; i <= 2 0 ; ++i )
5 {
6 n1 = ? ;
7 d1 = ? ;
8 s += n1 / d1 ;
9 }
10 p r i n t f ( ” s=%f \n” , s ) ;

C Programming 30 / 50
Example 2 (5)
• Given following series of fraction
• 21 , 32 , 35 , 85 , 13 21
8 , 13 ,· · ·
• Work out the sum of first 20 terms
• The full story
1 #i n c l u d e < s t d i o . h>
2 i n t main ( )
3 {
4 f l o a t n1 = 2 , n2 = 3 ;
5 i n t d1 = 1 , d2 = 2 , i = 0 ;
6 f l o a t s = n1 / d1 + n2 / d2 ;
7 f o r ( i = 3 ; i <= 2 0 ; ++i ) 15 p r i n t f ( ” s=%f \n” , s ) ;
8 { 16 return 0;
9 n2 = n1 + n2 ; 17 }
10 d2 = d1 + d2 ;
11 s += n2 / d2 ;
12 n1 = n2 − n1 ;
13 d1 = d2 − d1 ;
14 }
15 }

C Programming 31 / 50
Example 3 (1)

• Output following figure

*
***
*****
*******
*****
***
*

C Programming 32 / 50
Example 3 (2)

• On the 1st line, we print 3 blanks and 1 star


• On the 2nd line, we print 2 blanks and 3 stars
• On the 3rd line, we print 1 blanks and 5 stars
• On the 4th line, we print 0 blank and 7 stars
• Do the following in reverse...
• There should be a loop controls of printing blanks of one line
• There should be a loop controls of printing stars of one line
• There should be a loop controls of printing all the lines
• How to organize them??

C Programming 33 / 50
Example 3 (3)

• There should be a loop controls of printing blanks of one line


• There should be a loop controls of printing stars of one line
• There should be a loop controls of printing all the lines
• How to organize them??
1 Loop print all lines
2 Loop print blank(s)
3 Loop print star(s)
4 End-Loop

C Programming 34 / 50
Example 3 (4)

1 Loop print all lines


2 Loop print blank(s)
3 Loop print star(s)
4 End-Loop
1 We need a bound for the number of stars
2 We need a bound for the number of blanks
1 int n = 7 , i = 0 , j = 0;
2 i n t n s = 1 , nb = n −1;
3 f o r ( i = 0 ; i < n ; i ++)
4 {
5 ...
6 }

C Programming 35 / 50
Example 3 (5)
1 Print things to the bounds
int n = 5 , i = 0 , j = 0; nb += 2 ; //<−−why ?
i n t n s = 1 , nb = n −1; n s −= 4 ; //<−−why ?
f o r ( i = 0 ; i < n ; i ++) f o r ( i = 0 ; i < n ; i ++)
{ {
f o r ( j = 0 ; j < nb ; j ++) f o r ( j = 0 ; j < nb ; j ++)
{ {
printf (” ”) ; printf (” ”) ;
} }
f o r ( j = 0 ; j < n s ; j ++) f o r ( j = 0 ; j < n s ; j ++)
{ {
p r i n t f ( ”∗” ) ; p r i n t f ( ”∗” ) ;
} }
n s += 2 ; n s −= 2 ;
nb−−; nb++;
p r i n t f ( ” \n” ) ; p r i n t f ( ” \n” ) ;
} }

C Programming 36 / 50
Example 4 (1): solving by exhaustive search

• 30 people dine together, 50 cents are paid


• It takes 3 cents for a gentleman
• It takes 2 cents for a lady
• It takes 1 cent for a child
• How many gentlemen, ladies and children are there

3 ∗ x + 2 ∗ y + z = 50
x + y + z = 30

• We are actually trying to solve linear equations


• Notice that only integer solutions are valid

C Programming 37 / 50
Example 4 (2): solving by exhaustive search

• Solution is, we enumerate all possible solution


• To see whether they satisfy all the equations

3 ∗ x + 2 ∗ y + z = 50
x + y + z = 30

• Enumerate x from 1 to 30
• Enumerate y from 1 to 30
• Enumerate z from 1 to 30
• Now let’s do it!

C Programming 38 / 50
Example 4 (3): solving by exhaustive search
• Enumerate x from 1 to 30
• Enumerate y from 1 to 30
• Enumerate z from 1 to 30

3 ∗ x + 2 ∗ y + z = 50
x + y + z = 30

f o r ( x = 0 ; x <= 3 0 ; x++)
{
f o r ( y = 0 ; y <= 3 0 ; y++)
{
f o r ( z = 0 ; z <= 3 0 ; z++)
{
....
}
}
}

C Programming 39 / 50
Example 4 (4): solving by exhaustive search
1 #i n c l u d e < s t d i o . h>
2 i n t main ( )
3 {
4 i n t x = 0 , y = 0 , z = 0 , c1 = 0 , c2 = 0 ;
5 f o r ( x = 0 ; x <= 3 0 ; x++)
6 { f o r ( y = 0 ; y <= 3 0 ; y++)
7 { f o r ( z = 0 ; z <= 3 0 ; z++)
8 {
9 c1 = 3∗ x+2∗y+z ;
10 c2 = x+y+z ;
11 i f ( c1 == 50 && c2 == 3 0 )
12 {
13 p r i n t f ( ” x = %d , y = %d , z = %d\n” , x , y , z ) ;
14 }
15 } // f o r ( z )
16 } // f o r ( y )
17 } // f o r ( x )
18 }

C Programming 40 / 50
Example 4 (5): solving by exhaustive search
1 #i n c l u d e < s t d i o . h>
2 i n t main ( )
3 {
4 i n t x = 0 , y = 0 , z = 0 , c1 = 0 , c2 = 0 ;
5 f o r ( x = 0 ; x < 1 7 ; x++) //<−− why ??
6 { f o r ( y = 0 ; y <= 2 5 ; y++) //<−− why ??
7 { f o r ( z = 0 ; z <= 3 0 ; z++)
8 {
9 c1 = 3∗ x+2∗y+z ;
10 c2 = x+y+z ;
11 i f ( c1 == 50 && c2 == 3 0 )
12 {
13 p r i n t f ( ” x = %d , y = %d , z = %d\n” , x , y , z ) ;
14 }
15 } // f o r ( z )
16 } // f o r ( y )
17 } // f o r ( x )
18 }

C Programming 41 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 42 / 50
Try to avoid following case

• Be careful, this

1 w h i l e (1 > 0)
2 p r i n t f ( ” Did you m i s s me?\ n” ) ;

• Runs till the end of all days


• ∞ loops are common mistakes, and you will experience many of them
• Check for conditions that are always true
• By the way,

Do not be evil!
C Programming 43 / 50
Valid variants of for-loop (1)

• The arguments for the for loop are optional


• If you already have defined your iterating variable

int i = 1;
f o r ( ; i <= 1 0 ; ++i )
p r i n t f ( ”%d\n” , i ) ;

• Or if you have the iteration statement in your loop body

f o r ( i = 1 ; i <= 1 0 ; )
p r i n t f ( ”%d\n” , ++i ) ; /∗ seems more l i k e a w h i l e l o o p
∗/

C Programming 44 / 50
Valid variants of for-loop (2)

• If you’re not passing anything, it runs forever

for (;;)
p r i n t f ( ” I ’m s t i l l h e r e \n” ) ;

Note: the semicolons are still there.

C Programming 45 / 50
Outline

1 Loops
while loop
do-while loop
for loop
Examples of Loops

2 Miscellaneous

3 How to Debug

C Programming 46 / 50
Story behind Bug

C Programming 47 / 50
Overview about Programming Bugs (1)

• It happens!
• Two types of bugs
1 Grammar mistakes
2 Logic bugs
1 i n t main ( ) 1 i n t main ( )
2 { 2 {
3 int i = 0 , s = 0; 3 int i = 0, s ;
4 f o r ( i = 0 ; i < 5 ; i ++) 4 f o r ( i = 0 ; i < 5 ; i ++) ;
5 { 5 {
6 s += i ; 6 s += i ;
7 } 7 }
8 return 0; 8 return 0;
9 } 9 }

C Programming 48 / 50
Overview about Programming Bugs (2)
• From my humble point of view
• Two types of bugs
1 Non-memory leakage bugs
2 Memory leakage bugs
• Grammar mistakes are not bug!!
1 i n t main ( )
1 i n t main ( )
2 {
2 {
3 int i = 0;
3 int i = 0 , s = 0;
4 i n t ∗p = NULL ;
4 f o r ( i = 0 ; i < 5 ; i −−) ;
5 f o r ( i = 0 ; i < 5 ; i ++)
5 {
6 {
6 s += i ;
7 p = NULL ;
7 i f ( i % 2 == 1 ) ;
8 p = ( i n t ∗) malloc (
8 continue ;
sizeof ( int )) ;
9 }
9 }
10 return 0;
10 return 0;
11 }
11 }

C Programming 49 / 50
Debug by “printf()”
• From my humble point of view
• Two types of bugs
1 Non-memory leakage bugs
2 Memory leakage bugs
• Grammar mistakes are not bug!!
1 i n t main ( )
2 {
3 int i = 0 , s = 0;
4 p r i n t f ( ” bug 1 . 0 \ n” ) ;
5 f o r ( i = 0 ; i < 5 ; i −−) ;
6 {
7 s += i ;
8 p r i n t f ( ” bug 1 . 1 %d %d\n” , i , s ) ;
9 i f ( i % 2 == 1 ) ;
10 continue ;
11 }
12 p r i n t f ( ” bug 2 . 0 \ n” ) ;
13 return 0;
14 }

C Programming 50 / 50

You might also like