0% found this document useful (0 votes)
46 views3 pages

String and 2d Array

The document contains four C programming tasks related to matrix operations. The tasks include finding the sum of each row, printing the upper diagonal elements, calculating the sum of diagonal elements, and transposing a matrix. Each task is accompanied by sample input and expected output to illustrate the functionality.

Uploaded by

2024-1-60-167
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

String and 2d Array

The document contains four C programming tasks related to matrix operations. The tasks include finding the sum of each row, printing the upper diagonal elements, calculating the sum of diagonal elements, and transposing a matrix. Each task is accompanied by sample input and expected output to illustrate the functionality.

Uploaded by

2024-1-60-167
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Write a C Program to find the sum of all elements of each row of a matrix.

Sample Input:
Enter the number of rows and columns of the matrix: 3 3
Enter the elements of the matrix:
Enter element [0][0]: 1
Enter element [0][1]: 2
Enter element [0][2]: 3
Enter element [1][0]: 4
Enter element [1][1]: 5
Enter element [1][2]: 1
Enter element [2][0]: 1
Enter element [2][1]: 2
Enter element [2][2]: 3

Output:

Matrix:
123
451
123

Sum of each row:


Sum of row 1 = 6
Sum of row 2 = 10
Sum of row 3 = 6

2. Write a C Program to print upper diagonal of a matrix and user will give input.

Sample Input:
Enter the number of rows and columns of the matrix: 3 3
Enter the elements of the matrix:
Enter element [0][0]: 1
Enter element [0][1]: 2
Enter element [0][2]: 3
Enter element [1][0]: 4
Enter element [1][1]: 5
Enter element [1][2]: 6
Enter element [2][0]: 7
Enter element [2][1]: 8
Enter element [2][2]: 9
Output:

Upper Diagonal Elements of the Matrix:


123
56
9

3. Write a C program to find the sum of the diagonal elements.

Sample input:
Enter the number of rows and columns of the matrix: 3 3
Enter the elements of the matrix:
Enter element [0][0]: 1
Enter element [0][1]: 2
Enter element [0][2]: 3
Enter element [1][0]: 4
Enter element [1][1]: 5
Enter element [1][2]: 6
Enter element [2][0]: 7
Enter element [2][1]: 8
Enter element [2][2]: 9

Matrix:
1 2 3
4 5 6
7 8 9

Output:
Diagonal elements: 1 5 9
Sum of diagonal elements: 15
4. Write a C program to transpose a matrix.

Sample Input:
Enter the number of rows and columns of the matrix: 2 2
Enter the elements of the matrix:
Enter element [0][0]: 1
Enter element [0][1]: 2
Enter element [1][0]: 3
Enter element [1][1]: 4

Original Matrix:
12
34

Output:
Transposed Matrix:
13
24

You might also like