Determine the code below, tell me exactly how many times is
the operation sum++ performed ?

for ( i = 0; i < 100; i++ )
for ( j = 100; j > 100 - i; j--)
sum++;

Answer Posted / lnk

Its quite simple to analyse ...

LOOP i=0: i=0
then enters loop j=o: but it false that always J>100-i;

i.e.., i=0;j=100; 100- i-> 100
so always 100 is not greater than 100

than it comes out no sum++;
Loop i=1; ; j =100 only now 100 - i =99 so j>100 -i
(100>99)
then sum++ is executed ;


i= 1 j=100 j > 100 - i j=99 ;sum ++
i=2 j =99 j> 100 - i j =98 ; sum ++

i=50 j=51 j>100-50 true ( 51>50 ) ; sum++ j=50
i=51 j= 50 j>100-51 true(50>49 ) so no sum++


i = 99 j=2 j>100-i true (2>1) sum ++

so sum++ would be executed 99 times

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

using only #include and #include Write a program in C that will read an input from the user and print it back to the user if it is a palindrome. The string ends when it encounters a whitespace. The input string is at most 30 characters. Assume the string has no spaces and distinguish between and lowercase. So madam is a palindrome, but MadAm is not a palindrome. Use scanf and %s to read the string. Sample Test: Enter a string: madam madam is a palindrome. Enter a string: 09023 09023 is not a palindrome.

1304


What is pointer in c?

731


What is dynamic memory allocation?

802


What is the use of header?

614


How do I get a null pointer in my programs?

613






Are the variables argc and argv are always local to main?

568


c language interview questions & answer

1455


What is difference between stdio h and conio h?

877


Can a pointer point to null?

582


What is define directive?

634


What is c system32 taskhostw exe?

582


In C, What is the #line used for?

1045


Why header files are used?

639


What are the 5 elements of structure?

557


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

897