Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is chain pointer in c?

1060


why we wont use '&' sing in aceesing the string using scanf

2372


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

2247


What does d mean?

1087


What is the size of enum in c?

1116


What is an array? What the different types of arrays in c?

1185


what is the structure pointer?

2123


Explain can static variables be declared in a header file?

1151


What are the types of macro formats?

1120


Why we use int main and void main?

1078


What is realloc in c?

1098


Explain how can a program be made to print the name of a source file where an error occurs?

1197


Why is c not oop?

978


How can you determine the size of an allocated portion of memory?

1299


What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.

2258