Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array sum calculation
What is the output of this C program that sums elements of an integer array?
C
#include <stdio.h> int main() { int arr[] = {1, 2, 3, 4, 5}; int sum = 0; for (int i = 0; i < 5; i++) { sum += arr[i]; } printf("%d\n", sum); return 0; }
Attempts:
2 left
💡 Hint
Add all numbers in the array: 1 + 2 + 3 + 4 + 5.
✗ Incorrect
The loop adds each element of the array to sum. The total is 1+2+3+4+5 = 15.
❓ Predict Output
intermediate2:00remaining
Output of array element modification
What is the output of this C program that modifies elements of an array?
C
#include <stdio.h> int main() { int arr[3] = {10, 20, 30}; for (int i = 0; i < 3; i++) { arr[i] = arr[i] * 2; } for (int i = 0; i < 3; i++) { printf("%d ", arr[i]); } return 0; }
Attempts:
2 left
💡 Hint
Each element is multiplied by 2.
✗ Incorrect
The loop doubles each element, so 10->20, 20->40, 30->60.
❓ Predict Output
advanced2:00remaining
Output of searching for an element in array
What is the output of this C program that searches for a value in an array?
C
#include <stdio.h> int main() { int arr[] = {5, 10, 15, 20, 25}; int target = 15; int found = 0; for (int i = 0; i < 5; i++) { if (arr[i] == target) { found = 1; break; } } if (found) { printf("Found\n"); } else { printf("Not Found\n"); } return 0; }
Attempts:
2 left
💡 Hint
Check if 15 is in the array.
✗ Incorrect
The program finds 15 in the array and prints "Found".
❓ Predict Output
advanced2:00remaining
Output of array reversal
What is the output of this C program that reverses an array and prints it?
C
#include <stdio.h> int main() { int arr[] = {1, 2, 3, 4}; int n = 4; for (int i = 0; i < n / 2; i++) { int temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } return 0; }
Attempts:
2 left
💡 Hint
The program swaps elements from start and end.
✗ Incorrect
The array is reversed, so the output is "4 3 2 1 ".
🧠 Conceptual
expert2:00remaining
Number of elements in a statically declared array
Given the declaration
int arr[10];, what is the value of sizeof(arr) / sizeof(arr[0]) in C?Attempts:
2 left
💡 Hint
sizeof(arr) gives total bytes, sizeof(arr[0]) gives bytes per element.
✗ Incorrect
The expression calculates the number of elements by dividing total size by element size, which is 10.