1D Array Programs Questions Only
1D Array Programs Questions Only
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
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
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
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
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
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
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
Output :1