What Does This C Code Do? - Click Quiz - Statistics

General Stats
  • This quiz has been taken 18 times
  • The average score is 7 of 12
Answer Stats
Hint Answer % Correct
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) { if(a[i] % 2 == 0) r += a[i]; }
printf("%d\n", r);
Prints the sum of all even numbers in an array of integers
77%
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a * b);
Reads two integers from stdin and prints their product
77%
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) r += a[i];
printf("%d\n", r);
Prints the sum of an array of integers
69%
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) r += a[i];
r /= sizeof(a) / sizeof(a[0]);
printf("%d\n", r);
Prints the average of an array of integers
62%
int a[5] = {1, 2, 3, 4, 5}, r = 0;
for(int i = 0; i < 5; i++) { if(a[i] % 2 == 1) r += a[i]; }
printf("%d\n", r);
Prints the sum of all odd numbers in an array of integers
62%
char a[20];
gets(a);
int j = 0;
for(int i = 0; a[i]; i++) { if(a[i] >= 'A' && a[i] <= 'Z') a[j++] = a[i]; }
a[j] = 0;
puts(a);
Reads a string from stdin, discards all chars that aren't uppercase letters, then prints the new string
62%
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
Reads two integers from stdin and prints their sum
62%
int a = 1, b = 1;
printf("%d %d ", a, b);
for(int i = 3; i <= 10; i++) { int t = a; a = b; b = t; a = a + b; printf("%d ", a); }
printf("\n");
Prints the first 10 numbers in the Fibonacci sequence
54%
char a[20];
gets(a);
for(int i = 0; a[i]; i++) { if(i % 2 == 0) putchar(a[i]); }
putchar('\n');
Reads a string from stdin and prints every other character
54%
char a[20];
int r = 0;
gets(a);
while(a[r]) r++;
printf("%d\n", r);
Reads a string from stdin and prints its length
54%
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", (a > b) ? a : b);
Reads two integers from stdin and prints the maximum of those integers
54%
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", (a < b) ? a : b);
Reads two integers from stdin and prints the minimum of those integers
54%
No matching quizzes found
Score Distribution
Percent of People with Each Score
Percentile by Number Answered
Your Score History
You have not taken this quiz