Find the output of the following program

Provide the output of the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>

int main()

{

int val[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int sum = 0;

int i;

for( val[4] = 0; val[4] < 10; val[4]++) {

val[val[4]] = val[4] * 2;

}

for( i = 0; i < 10; i++) {
   sum = sum + val[i];
 }
 printf( "%d", sum);

}

PS: Do not use your C environment or computer.


The answer is 40.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Hasmik Garyaka
Sep 19, 2017

At the end of program array is [0 2 4 6 10 0 0 0 0 18].

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...