1D Arrays-Scenario based questions and examples
1D Arrays-Scenario based questions and examples
int main() {
int sales[7]; // Array to store sales for 7 days
int max;
max = sales[0];
for (int i = 1; i < 7; i++) {
if (sales[i] > max) {
max = sales[i];
}
}
return 0;
}
2. Calculate the Average of Numbers
Scenario: A teacher wants to find the average marks of students in a class.
Example Program:
#include <stdio.h>
int main() {
int marks[5]; // Array to store marks of 5 students
int sum = 0;
float average;
return 0;
}
3. Count Even and Odd Numbers
Scenario: A user wants to count how many numbers in a list are even or odd.
Example Program:
#include <stdio.h>
int main() {
int numbers[10];
int evenCount = 0, oddCount = 0;
printf("Enter 10 numbers:\n");
for (int i = 0; i < 10; i++)
{
scanf("%d", &numbers[i]);
if (numbers[i] % 2 == 0)
{
evenCount++;
}
else {
oddCount++;
}
}
return 0;
}
Reverse the Elements of an Array
Scenario: A user wants to see the order of items reversed, such as reversing the list of steps
taken each day.
Example Program:
c
Copy code
#include <stdio.h>
int main() {
int steps[7];
return 0;
}