0% found this document useful (0 votes)
15 views

1D Arrays-Scenario based questions and examples

Uploaded by

Vimal EA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

1D Arrays-Scenario based questions and examples

Uploaded by

Vimal EA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1D Arrays

1. Identify Pass and Fail Students


Scenario: A teacher wants to know how many students passed and failed in a class based
on their scores. A score >= 40 is considered a pass.

2. Find the First Repeated Element


Scenario: A user wants to find the first repeated number in an array of integers.
Example Question: Write a program to find the first repeated element in a list of 10
integers. If no repetition exists, output "No Repeated Element."
3. Find the median in given array of size ‘N’. N is the input entered by the user.
a. Hint- Sort the array
b. Apply separate formula if the array size is even
c. Apply separate formula if the array size is odd
1. Find the Maximum Number in an Array
Scenario: A shopkeeper wants to find the highest sale amount from a list of daily sales.
Example Program:
#include <stdio.h>

int main() {
int sales[7]; // Array to store sales for 7 days
int max;

printf("Enter sales for 7 days:\n");


for (int i = 0; i < 7; i++) {
scanf("%d", &sales[i]);
}

max = sales[0];
for (int i = 1; i < 7; i++) {
if (sales[i] > max) {
max = sales[i];
}
}

printf("The highest sale amount is: %d\n", max);

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;

printf("Enter marks of 5 students:\n");


for (int i = 0; i < 5; i++) {
scanf("%d", &marks[i]);
sum += marks[i];
}

average = sum / 5.0;

printf("The average marks are: %.2f\n", 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++;
}
}

printf("Even numbers: %d\n", evenCount);


printf("Odd numbers: %d\n", 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];

printf("Enter the steps taken each day for 7 days:\n");


for (int i = 0; i < 7; i++) {
scanf("%d", &steps[i]);
}

printf("Steps in reverse order:\n");


for (int i = 6; i >= 0; i--) {
printf("%d ", steps[i]);
}
printf("\n");

return 0;
}

You might also like