0% found this document useful (0 votes)
0 views5 pages

1D Array Programs Questions Only

The document outlines various array-related programming scenarios, including calculating sums, finding maximum and minimum values, counting even and odd numbers, reversing arrays, searching for elements, copying arrays, counting positive and negative numbers, calculating averages, and counting duplicates. Each scenario includes a problem description, input/output format, and several test cases for validation. The examples provided illustrate the expected functionality of the programs.

Uploaded by

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

1D Array Programs Questions Only

The document outlines various array-related programming scenarios, including calculating sums, finding maximum and minimum values, counting even and odd numbers, reversing arrays, searching for elements, copying arrays, counting positive and negative numbers, calculating averages, and counting duplicates. Each scenario includes a problem description, input/output format, and several test cases for validation. The examples provided illustrate the expected functionality of the programs.

Uploaded by

sinh.anand2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Array programs

1.
Scenario:
A store records daily sales in an array. You need to find the total sales.

Problem Description:
Given N integers, find the sum of all array elements.

Input Format:
- Integer N (size of array)
- Next N integers

Output Format:
- Print sum of elements

Sample Input/Output:
Input: 5 10 20 30 40 50
Output: 150

Test Cases:
1. Input: 5 1 2 3 4 5 → Output: 15
2. Input: 4 10 20 30 40 → Output: 100
3. Input: 3 5 5 5 → Output: 15
4. Input: 6 0 1 2 3 4 5 → Output: 15
5. Input: 5 -1 -2 3 4 5 → Output: 9
2.A teacher wants to know the highest mark among students.

Problem Description:
Find the largest number in the array.

Sample Input/Output:
Input: 5 10 25 12 30 18
Output: 30

Test Cases:
1. Input: 5 1 2 3 4 5 → Output: 5
2. Input: 4 10 50 30 20 → Output: 50
3. Input: 3 -1 -2 -3 → Output: -1
4. Input: 6 9 8 10 15 7 5 → Output: 15
5. Input: 5 100 200 150 250 50 → Output: 250

3.A warehouse wants to find the least stock available.

Problem Description:
Find the smallest number in the array.

Sample Input/Output:
Input: 5 10 5 15 8 20
Output: 5

Test Cases:
1. Input: 5 10 20 30 5 40 → Output: 5
2. Input: 4 -1 0 1 2 → Output: -1
3. Input: 3 7 7 7 → Output: 7
4. Input: 6 100 99 98 97 96 95 → Output: 95
5. Input: 5 3 2 1 4 5 → Output: 1
4. A data analyst wants to count even and odd elements in an array.

Sample Input/Output:
Input: 6 1 2 3 4 5 6
Output:
Even: 3
Odd: 3

Test Cases:
1. Input: 5 1 3 5 7 9 → Even: 0 Odd: 5
2. Input: 4 2 4 6 8 → Even: 4 Odd: 0
3. Input: 6 1 2 3 4 5 6 → Even: 3 Odd: 3
4. Input: 3 10 11 12 → Even: 2 Odd: 1
5. Input: 5 0 5 10 15 20 → Even: 3 Odd: 2

5. A student wants to print the roll numbers in reverse order.

Sample Input/Output:
Input: 5 1 2 3 4 5
Output: 5 4 3 2 1

Test Cases:
1. Input: 4 10 20 30 40 → Output: 40 30 20 10
2. Input: 5 1 3 5 7 9 → Output: 9 7 5 3 1
3. Input: 3 9 8 7 → Output: 7 8 9
4. Input: 6 5 10 15 20 25 30 → Output: 30 25 20 15 10 5
5. Input: 5 2 4 6 8 10 → Output: 10 8 6 4 2

6. Search an Element in Array


Scenario:
You need to check if a number exists in the array.

Sample Input/Output:
Input: 5 10 20 30 40 50 30
Output: Element found

Test Cases:
1. Input: 5 1 2 3 4 5 3 → Element found
2. Input: 4 10 20 30 40 50 → Element not found
3. Input: 3 5 5 5 5 → Element found
4. Input: 6 9 8 7 6 5 4 8 → Element found
5. Input: 5 10 20 30 40 50 60 → Element not found

7. Copy Elements from One Array to Another


Scenario:
A system needs to back up user data into another array.

Sample Input/Output:
Input: 5 1 2 3 4 5
Output: 1 2 3 4 5

Test Cases:
1. Input: 5 1 2 3 4 5 → Output: 1 2 3 4 5
2. Input: 4 10 20 30 40 → Output: 10 20 30 40
3. Input: 3 5 10 15 → Output: 5 10 15
4. Input: 6 7 14 21 28 35 42 → Output: 7 14 21 28 35 42
5. Input: 5 -1 -2 -3 -4 -5 → Output: -1 -2 -3 -4 -5

8. Count Positive and Negative Numbers


Scenario:
A financial analyst needs to count profits (positive) and losses (negative).

Sample Input/Output:
Input: 6 -1 2 -3 4 -5 6
Output:
Positive: 3
Negative: 3

Test Cases:
1. Input: 5 1 -1 2 -2 3 → Positive: 3 Negative: 2
2. Input: 4 -5 -10 15 20 → Positive: 2 Negative: 2
3. Input: 6 0 1 -1 2 -2 3 → Positive: 3 Negative: 2
4. Input: 3 -1 -2 -3 → Positive: 0 Negative: 3
5. Input: 5 10 20 30 40 50 → Positive: 5 Negative: 0

9. Calculate Average of Array Elements


Scenario:
A teacher wants to calculate the average marks of students.

Sample Input/Output:
Input: 5 10 20 30 40 50
Output: 30.00
Test Cases:
1. Input: 5 1 2 3 4 5 → Output: 3.00
2. Input: 4 10 20 30 40 → Output: 25.00
3. Input: 3 5 10 15 → Output: 10.00
4. Input: 6 10 20 30 40 50 60 → Output: 35.00
5. Input: 5 0 0 0 0 0 → Output: 0.00

[Link] to print count of duplicate element in array.


Input:10 20 10 30 40 50

Output :1

You might also like