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 / abdur rab
for ( i = 0; i < 100; i++ )
for ( j = 100; j > 100 - i; j--)
sum++;
first iteration i = 0
j = 100
j loop is executed untill ( 100 - i ) (ie 100 - 0 = 100 )
so output is 0 ( sum is incremented 0 times )
second iteration i = 1
j = 100
j loop is executed untill ( 100 - i ) (ie 100 - 1 = 99 )
so output is 1 ( sum is incremented 1 times )
third iteration i = 2
j = 100
j loop is executed untill ( 100 - i ) (ie 100 - 2 = 98 )
so output is 1 ( sum is incremented 2 times )
0 + 1 + 2 + 3.......+ 99 = ( n (n+1) ) / 2
( 99 (99+1) ) / 2 = 4950
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
Design a program which assigns values to the array temperature. The program should then display the array with appropriate column and row headings.
Where define directive used?
What are the features of c languages?
how to print the character with maximum occurence and print that number of occurence too in a string given ?
Write a program to identify if a given binary tree is balanced or not.
to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?
What is structure in c explain with example?
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
What is c language used for?
Is anything faster than c?
Explain what is operator promotion?
Write a program to use switch statement.
Explain how do you declare an array that will hold more than 64kb of data?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
Why does not c have an exponentiation operator?