- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a C program to perform 3X3 matrix operations
Problem
Enter any 9 numbers at runtime and add the numbers in a row, column, and diagonal wise by using C Programming language
Algorithm
Step 1: Declare 9 variables Step 2: enter 9 numbers at runtime Step 3: store the numbers in 3 X 3 matrix form //x y z p q r a b c Step 4: Do row calculation: add all the numbers in a row and print // (x+y+z),(p+q+r),(a+b+c) Step 5: Do column calculation: add all the numbers in a Column and print //(x+p+a)(y+q+b)(z+r+c) Step 6: Do Diagonal Calculation: add the numbers in diagonal and print //(x+q+c),(a+q+z)
Program
#include<stdio.h> int main(){ int x,y,z,p,q,r,a,b,c; printf(“enter any 9 numbers :
"); scanf(“%d%d%d%d%d%d%d%d%d",&x,&y,&z,&p,&q,&r,&a,&b,&c);//reading all 9 integers printf(“%d %d %d
",x,y,z); printf(“%d %d %d
",p,q,r); printf(“%d %d %d
",a,b,c); printf(“Row total:%d %d %d
",(x+y+z),(p+q+r),(a+b+c));//row calculation printf(“column total: %d %d %d
",(x+p+a),(y+q+b),(z+r+c));//column calculation printf(“diagonal total :%d %d
",(x+q+c),(a+q+z));//Diagonal calculation return 0; }
Output
enter any 9 numbers : 2 4 6 3 5 7 8 9 2 2 4 6 3 5 7 8 9 2 Row total:12 15 19 column total: 13 18 15 diagonal total :9 19
Advertisements