Computer Programming Solved C++
Computer Programming Solved C++
Exercises/Lab Journal # 11
Task 1
Declare an array of 4 by 5 size of integers and get user input to fill the array values.
Then, find the minimum values in the arrays.
Code:
#include <iostream>
using namespace std;
int main()
{
int arr[4][5], min = INT_MAX;
for (int i = 0; i < 4; i++) //i<4 for number of rows
{
for (int j = 0; j < 5; j++) //j<5 for number of columns
{
cout << "enter the " << i + 1 << "x" << j + 1 << " element: ";
cin >> arr[i][j];
if (arr[i][j] < min) min = arr[i][j];
cout << endl;
}
}
cout << min << " is the smallest element in the given array";
return 0;
}
Output:
Task 2
Write a program to input value in an array of type integer and size 6 by 7. Find out
the total number of even and odd values entered in the array.
Code:
#include <iostream>
using namespace std;
int main()
{
int arr[6][7], even = 0, odd = 0;
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 7; j++)
{
cout << "enter the " << i + 1 << "x" << j + 1 << " element: ";
cin >> arr[i][j];
if (arr[i][j] % 2 == 0) even++;
else odd++;
cout << endl;
}
}
cout << "total even numbers are " << even << endl;
cout << "total odd numbers are " << odd;
return 0;
}
Output:
THE END