0% found this document useful (0 votes)
20 views

C Programme For Array

The program allows the user to select an operation to perform on numbers or matrices, including addition, subtraction, multiplication, division, and remainder on numbers, and addition, subtraction, and multiplication on 3x3 matrices. The user enters the numbers or matrix elements, and the program displays the result. It uses arrays to store the matrix elements and perform the operations on the matrices.

Uploaded by

haqjmi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

C Programme For Array

The program allows the user to select an operation to perform on numbers or matrices, including addition, subtraction, multiplication, division, and remainder on numbers, and addition, subtraction, and multiplication on 3x3 matrices. The user enters the numbers or matrix elements, and the program displays the result. It uses arrays to store the matrix elements and perform the operations on the matrices.

Uploaded by

haqjmi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

THIS PROGRAMME IS FOR MATRIX

#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int mat1[3][3],mat2[3][3], mat3[3][3];
int choice,a,b;
int i,j,k;
clrscr();
printf("Press 1 for Addition two Numbers\n");
printf("Press 2 for Subtraction two Numbers\n");
printf("Press 3 for Multiplication two numbers\n");
printf("Press 4 for Division two numbers\n");
printf("Press 5 for Remainder two numbers\n");
printf("Press 6 for Matrix Addition\n");
printf("Press 7 for Matrix Subtraction\n");
printf("Press 8 for Matrix MUltiplication\n");
printf("Press 9 for EXIT");
printf("\nEnter Your Choice\n\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter Two Numbers for Addition\n");
scanf("%d%d",&a,&b);
printf("The Addition of two Numbers = %d",(a+b));
break;
case 2:
printf("Enter Two Numbers for Subtraction\n");
scanf("%d%d",&a,&b);
printf("The Subtraction of two Numbers = %d",(a-b));
break;
case 3:
printf("Enter Two Numbers for Multiplication\n");
scanf("%d%d",&a,&b);
printf("The Multiplication of two Numbers = %d",(a*b));
break;
case 4:
printf("Enter Two Numbers for Division\n");
scanf("%d%d",&a,&b);
printf("The Division of two Numbers = %d",(a/b));
break;
case 5:
printf("Enter Two Numbers for Remainder\n");
scanf("%d%d",&a,&b);
printf("The Remainder of two Numbers = %d",(a%b));
break;
case 6:

printf("\nEnter Elements of the first Matrix\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat1[i][j]);
}
}
printf("Your first Matrix is as follows\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n\n");
}
printf("Enter Elements of the SEcond Matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat2[i][j]);
}
}
printf("Your Second Matrix is as follows\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n\n");
}
printf("Matrix Addition is as follows:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
mat3[i][j] = mat1[i][j] + mat2[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat3[i][j]);
}
printf("\n\n");
}
break;
case 7:
printf("\nEnter Elements of the first Matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

{
scanf("%d",&mat1[i][j]);
}
}
printf("Your first Matrix is as follows\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n\n");
}
printf("Enter Elements of the SEcond Matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat2[i][j]);
}
}
printf("Your Second Matrix is as follows\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n\n");
}
printf("Matrix Subtraction is as follows:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
mat3[i][j] = mat1[i][j] - mat2[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat3[i][j]);
}
printf("\n\n");
}
break;
case 8:
printf("\nEnter Elements of the first Matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat1[i][j]);
}
}

printf("Your first Matrix is as follows\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n\n");
}
printf("Enter Elements of the Second Matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat2[i][j]);
}
}
printf("Your Second Matrix is as follows\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n\n");
}
printf("Matrix Multiplication is as follows:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
mat3[i][j]=0;
for(k=0;k<3;k++)
{
mat3[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",mat3[i][j]);
}
printf("\n\n");
}
break;
case 9: exit(0);
default :printf("\nWrong Choice Please try again");
}
getch();
}

RESULT

You might also like