Quiz on Arrays.
Question 1: What is the output?
int a[10];
a[0]=3; a[1]=20; a[2]=14; a[3]=0;
printf("%d %d %d",a[1],a[3],a[0]);
20 0 3
Question 2: What is the output?
int a[10]; int i;
a[0]=3; a[1]=20; a[2]=14; a[3]=0; i = 2;
printf("%d %d %d %d",a[i],a[i+1],a[i]+1,a[i-2]);
14 0 15 3
Question 3: What is the output?
int a[10]; int i;
a[0]=3; a[1]=20; a[2]=14; a[3]=0; i = 2;
printf("%d",a[i]*a[i-1]-a[i-2]);
317
Question 4: What is the output?
int a[10]; int i;
a[0]=3; a[1]=20; a[2]=14; a[3]=0;
i=a[3]; a[3]=a[2]; a[2]=i;
printf("%d %d %d %d",a[2],a[3],a[i],a[a[i]]);
0 14 3 14
Question 5: What is the output?
int a[10]; int i=0;
while ( i < 10 ) {
a[i] = 9 - i; i++;
}
printf("%d %d",a[2],a[5]);
7 4
Question 6: What is the output?
int a[10]; int i=0;
while ( i < 10 ) {
a[i] = i*i+3*i-1; i++;
}
printf("%d %d",a[2],a[5]);
9 39
Question 7: What is the output?
int a[10] = {5, 1, 3, 2, 9, 6, 2, 2, 6, 7};
i = 0; j = -1;
while ( i < 10 ) {
if ( a[i] > j ) j = a[i]; i++;
}
printf("%d",j);
9
Question 8: What is the output?
int a[10] = {5, 1, 3, 2, 9, 6, 2, 2, 6, 7};
i = 0; j = 0;
while ( i < 10 ) {
if ( a[i] == 2 ) j = j+1; i++;
}
printf("%d",j);
3
Question 9: What is the output?
int a[10] = {5, 1, 3, 2, 9, 6, 2, 2, 6, 7};
i = 0; j = 0;
while ( i < 10 ) {
j = j + a[i]; i++;
}
printf("%d",j);
43
Question 10: What is the output?
int a[10] = {5, 1, 3, 2, 9, 6, 2, 2, 6, 7};
i = 0; j = 0;
while ( i < 10 ) {
if ( a[i] > j ) j = j + a[i]; i++;
}
printf("%d",j);
14