Professional Documents
Culture Documents
#include <iostream>
int main() {
int matrix[4][4];
cout << "Enter value for row " << i + 1 << " column " << j + 1 << ": ";
int transpose[4][4];
transpose[j][i] = matrix[i][j];
return 0;
Write a program that creates and then reads a matrix of 5 rows and 5 columns of type int. while reading;
the program should not accept values greater than 100. For any entered value greater than 100, the
program should ask for input repeatedly. After reading all numbers, the system should find the
smallestnumber in the matrix and its location or index values. The program should print the smallest
number and its location (row and column) and also print their count.
#include <iostream>
int main() {
int rows = 5;
int cols = 5;
int matrix[rows][cols];
do {
cout << "Enter value for row " << i + 1 << " column " << j + 1 << ": ";
cout << "Please enter a value less than or equal to 100." << endl;
int countSmallest = 0;
smallest = matrix[i][j];
smallestRow = i;
smallestCol = j;
if (matrix[i][j] == smallest) {
countSmallest++;
cout << "\nSmallest number in the matrix: " << smallest << endl;
cout << "Location (Row, Column): (" << smallestRow + 1 << ", " << smallestCol + 1 << ")" << endl;
return 0;
Write a C++ program that displays the row numbers of a matrix containing at least two even numbers.
First, the program should create a 2D array (5 rows, 5 columns). Then, ask the user to input values in the
matrix or 2D array. After that, program should display row number (or index) which have less than 2
prime numbers. If no row (of the matrix) contains at least two prime numbers then the program should
display the message “No row found containing two prime numbers”. Sample Input: Please enter data for
matrix of 5 x 5: 2 6 18 49 8 33 15 11 17 13 8 21 47 37 28 12 12 12 12 12 2 3 4 5 6 Sample Output: Row
number 1, 4 contains prime numbers less than 2.
#include <iostream>
using namespace std;
int main() {
int rows = 5;
int cols = 5;
int matrix[rows][cols];
cout << "Please enter data for matrix of 5 x 5:" << endl;
if (matrix[i][j] % 2 == 0) evenCount++;
if (matrix[i][j] % k == 0) {
isPrime = false;
break;
if (!found) cout << "No row found containing two prime numbers";
else cout << " contains prime numbers less than 2." << endl;
return 0;