Knowledge Institute of Technology
40
40
40
40
Name: MUKESHKALAI E Scan to verify results
Email: 2k23eee40@kiot.ac.in
Roll no: 40
Phone: 9360840794
Branch: Knowledge Institute of Technology
Department: EEE
Batch: 2027
Degree: BE EEE
2023_27_IV_EEE_OOPS Using CPP
40
40
40
40
KIOT_CPP_Unit 1_COD_Arrays
Attempt : 1
Total Mark : 20
Marks Obtained : 20
Section 1 : Coding
1. Problem Statement
Imagine you are a teacher at a school and you want to analyze the
40
40
40
40
performance of your students in a recent test. You have collected the test
scores of N students and stored them in an array. Now, you want to select
a particular student's score and analyze it further.
For the selected score, calculate and display the following:
The number of students who scored higher than the selected score.The
number of students who scored lower than the selected score.The number
of students whose score is exactly divisible by the selected score.
Write a program to accomplish the given tasks.
Input Format
40
40
40
40
The first line of input consists of an integer N, representing the number of
students.
40
40
40
40
The second line of input consists of N space-separated integers, representing
the scores of students.
The third line of input consists of an integer representing the selected score.
Output Format
The first line of output prints the number of students who scored higher than the
selected score.
The second line prints the number of students who scored lower than the
selected score.
40
40
40
40
The third line prints the number of students whose score is exactly divisible by
the selected score.
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 12
12 23 45 56 78 89 98 87 65 54 32 21
32
Output: Greater : 8
40
40
40
40
Lesser : 3
Exactly divisible : 1
Answer
// You are using GCC
// You are using GCC
#include <iostream>
using namespace std;
int main() {
int N, selectedScore;
cin >> N;
40
40
40
40
int scores[N];
// Reading scores
40
40
40
40
for (int i = 0; i < N; i++) {
cin >> scores[i];
}
// Reading selected score
cin >> selectedScore;
// Counting
int greaterCount = 0, lesserCount = 0, divisibleCount = 0;
for (int i = 0; i < N; i++) {
if (scores[i] > selectedScore) {
greaterCount++;
40
40
40
40
} else if (scores[i] < selectedScore) {
lesserCount++;
}
if (scores[i] % selectedScore == 0) {
divisibleCount++;
}
}
// Printing results in correct format
cout << "Greater : " << greaterCount << endl;
cout << "Lesser : " << lesserCount << endl;
cout << "Exactly divisible : " << divisibleCount << endl;
40
40
40
40
return 0;
}
Status : Correct Marks : 10/10
2. Problem Statement
Raj is working on a matrix processing problem. He is given a matrix with
rows and columns dimensions and he needs to extract and print the
elements that are located on the boundary of the matrix.
The boundary elements are the ones that are in the first row, first column,
40
40
40
40
last column and last row of the matrix.
40
40
40
40
Help Raj write a program that accomplishes this task.
Input Format
The first line of input consists of two integers M and N, representing the
dimensions of the matrix.
The next M lines consist of N space-separated integers, representing the
elements of the matrix.
Output Format
The output displays a single line containing the boundary elements of the matrix,
separated by a space.
40
40
40
40
Refer to the sample output for formatting specifications.
Sample Test Case
Input: 2 3
4 8 12
6 9 14
Output: 4 8 12 6 9 14
Answer
40
40
40
40
// You are using GCC
// You are using GCC
//You are using GCC
#include <iostream>
using namespace std;
int main() {
int M, N;
cin >> M >> N;
int matrix[M][N];
// Input the matrix elements
40
40
40
40
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
cin >> matrix[i][j];
40
40
40
40
}
}
// Print the boundary elements
for (int j = 0; j < N; j++) { // First row
cout << matrix[0][j] << " ";
}
for (int i = 1; i < M-1; i++) { // Middle rows
cout << matrix[i][0] << " "; // First column
if (N > 1) {
cout << matrix[i][N-1] << " "; // Last column
}
40
40
40
40
}
if (M > 1) {
for (int j = 0; j < N; j++) { // Last row
cout << matrix[M-1][j] << " ";
}
}
return 0;
}
Status : Correct Marks : 10/10
40
40
40
40
40
40
40
40