LEA
LEARNING MODULE NO. 8 – POST TEST
POST Instructions: Answer the following questions as directed. Total of 100 points.
TEST
1. Develop a program using array that calculates the sum and average of the
three input values from the keyboard and prints the calculated sum and average.
Sample input/output dialogue:
Enter three numbers:
10 5 15
The sum is 30.
The average is 10.
#include<iostream>
using namespace std;
int main()
{
// declare variables
double 10, 5, 15;
double sum, average;
// take input from end-user
cout << "Enter three Numbers :: ";
LEARNING MODULE SURIGAO STATE
cin >> 10 >> 5 >> 15;
COLLEGE OF TECHNOLOGY
// calculate sum value
sum = 10 + 5 + 15;
// calculate average value
average = sum / 3;
// display result
cout << "Sum = " << sum << endl;
cout << "Average = " << average << endl;
return 0;
}
2. Develop a program using array that accepts three input values from the
keyboard. Then it should also accept a number to search. This number is to be
CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 1
LEA
searched if it is among the three input values. If it is found, display the message
“Search number is found!!!”, otherwise display “Search numbers is lost!!!.
Sample input/output dialogue:
Enter three numbers:
20 5 2
Enter the number to search: 2
Search number is found!!!
3. Develop a program using array that searches a number and display the
number of times it occurs on the list of 4 values.
Sample input/output dialogue:
Enter four values:
20 5 2 5
Enter a number: 5
Occurrences: 2
4. Develop a program using array that determines the highest and lowest of
the four input values.
LEARNINGSample
MODULE SURIGAO
input/output dialogue: STATE COLLEGE OF TECHNOLOGY
Enter four values:
20 5 2 5
The highest is : 20
The lowest is: 2
#include <stdio.h>
void main()
{
int arr1[100];
int i, mx, mn, n;
printf("\n\nFind maximum and minimum element in an
array :\n");
printf("--------------------------------------------------\n
");
printf("Input the number of elements to be stored in
the array :");
CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 2
LEA
scanf("%d",&n);
printf("Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}
mx = arr1[0];
mn = arr1[0];
for(i=1; i<n; i++)
{
if(arr1[i]>mx)
{
mx = arr1[i];
}
if(arr1[i]<mn)
{
LEARNING MODULE SURIGAO
mn STATE COLLEGE OF TECHNOLOGY
= arr1[i];
}
}
printf("Maximum element is : %d\n", mx);
printf("Minimum element is : %d\n\n", mn);
}
5. Develop a program that would add 2 matrices and display the sum on
screen. Use two-dimensional array in solving this problem.
Sample input/output dialogue:
Enter elements for the first matrix:
20 5 2 5
Enter elements for the second matrix:
10 2 3 1
The sum of two matrices:
30 7 5 6
CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 3
LEA
LEARNING MODULE SURIGAO STATE COLLEGE OF TECHNOLOGY
CpE 143 - COMPUTER PROGRAMMING (DR. ANALYN S. MORITE) 4