Professional Documents
Culture Documents
CP LAB #06 Assignment: Course: BS (CS) Class: 1-A .: 02-134212-041
CP LAB #06 Assignment: Course: BS (CS) Class: 1-A .: 02-134212-041
CP LAB #06 Assignment: Course: BS (CS) Class: 1-A .: 02-134212-041
LAB TASK#1:
Write a program to create a 2D array of size 3x3. The program takes input
for each cell in the array and then calculates and displays the sum of each
row.
For example:
123
456
789
Sum of first row is 6
Sum of second row is 15
Sum of third row would is 24
PROGRAM:
#include <cstdlib>
#include <iostream>
int sum;
sum = 0;
}
CSL-113: Computer Programming Lab
cin>>m;
cin>>n;
for(int j=0;j<n;j++)
cin>>arr[i][j];
}
CSL-113: Computer Programming Lab
rowSum(arr, m, n);
return 0;
OUTPUT:
CSL-113: Computer Programming Lab
LAB TASK#2::
Write a program that takes a 3x3 matrix as input and asks for
a number entered and prints out its position in the matrix. It
displays not found if the number is not in the matrix.
For example:
123
456
789
Input Example 1:
Enter a number to find: 4
Found! Position: [1] [0]
Input Example 2:
Enter a number to find: 0
Not Found
CSL-113: Computer Programming Lab
PROGRAM:
#include <iostream>
using namespace std;
main() {
int narr[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << "enter numbers for matrix: ";
cin >> narr[i][j];
}
}
bool foind = false;
int num;
cout << "enter number you want to search: ";
cin >> num;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (num == narr[i][j])
{
cout << "character" << num << " is found at position " << i <<
"x" << j << " in the matrix" << endl;
CSL-113: Computer Programming Lab
if (foind == false)
{
cout << "the number you want to search is not found in the
matrix " << endl;
system("pause");
}
CSL-113: Computer Programming Lab
OUTPUT:
LAB TASK#3:
Example:
123
456
789
Transpose:
147
258
369
PROGRAM:
#include <iostream>
cout << "Enter element a" << i + 1 << j + 1 << ": ";
if (j == column - 1)
transpose[j][i] = a[i][j];
if (j == row - 1)
CSL-113: Computer Programming Lab
return 0;
}
CSL-113: Computer Programming Lab
OUTPUT:
CSL-113: Computer Programming Lab
THE END