1,136 views
2 2 votes

Consider the following program

int find (int n)
{
  int a = 1;
  for (i = 1; i < = n; i ++)
     for (j = 1; j < = i; j++)
        for (k = 1; k <= j, k++)
            a = a + 1;                                 
  return a;
}

The value returned by find (9) is ______ .

2 Answers

Best answer
2 2 votes

$\sum_{i=1}^{n}\sum_{j=1}^{i}\sum_{k=1}^{j}1 = \sum_{i=1}^{n}\sum_{j=1}^{i}j = \sum_{i=1}^{n}(i*(i+1)) /2 =    1+3+6+10+15+21+28+36+45 = 165$

Now, initial value of a was 1. Now a value incremented 165 times by 1. So final ans = 1+165 = 166

//https://ide.geeksforgeeks.org/bo7T4PnEfn (If you want to check)

• selected by
0 0 votes
Nested For loop:

I=1     I=2      I=3      I=4……………………………  I=8    I=9

J=1     J=2     J=3     J=4…………………………… J=8   J=9

K=1    K=2    K=6      K=10………………………… K=36  K=45

 

Sum of all these you will get: 165

So now value of a increasing linearly with variable K. Now a=165+1 =166

Ans: 166
Position:
Show:

Related questions

3 3 votes
2 answers 2 answers
984
984 views
Parshu gate asked Nov 12, 2017
984 views
int i = 0 ;main( ){printf ( "\nmain's i = %d", i ) ;i++ ;val( ) ;printf ( "\nmain's i = %d", i ) ;val( ) ;}val( ){i = 100 ;printf ( "\nval's i = %d", i ) ;i++ ;}
0 0 votes
0 0 answers
667
667 views
Na462 asked Aug 22, 2018
667 views
What will be output ?A. Abnormal Termination.B. Infinite loopC. Output wil be 65536D. NoneAns. D
1 1 vote
1 answers 1 answer
1.6k
1.6k views
manisha11 asked Sep 10, 2018
1,602 views
/ find ouput *#include <stdio.h>int main(){ { int a [3] ={{ {2,4} , {7 ,8} , {3,4} }, {{2 ,2}, {2, 3},{2, 3},{3,4} } }; printf (...
0 0 votes
0 0 answers
1.2k
1.2k views
srestha asked Mar 7, 2018
1,205 views
#include<stdio.h int fun1(int x) { x=14; } int fun2(int x) { x=20; } int main() { int(*p)(),m,n; scanf("%d",&m); if(m) p=fun1; else p=fun2; n=(*p)(); printf("%d",n); retu...