0% found this document useful (0 votes)
9 views4 pages

2D ARRAY PROGRAMS

The document contains multiple C programs that perform various matrix operations, including calculating the sums of left and right diagonal elements, summing row elements, adding two matrices, finding minimum and maximum values, and transposing a matrix. Each program prompts the user for input, processes the matrix data, and outputs the results. The programs are structured with clear input and output sections, demonstrating fundamental matrix manipulations.
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)
9 views4 pages

2D ARRAY PROGRAMS

The document contains multiple C programs that perform various matrix operations, including calculating the sums of left and right diagonal elements, summing row elements, adding two matrices, finding minimum and maximum values, and transposing a matrix. Each program prompts the user for input, processes the matrix data, and outputs the results. The programs are structured with clear input and output sections, demonstrating fundamental matrix manipulations.
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/ 4

SUM OF LEFT DIAGONAL ELEMENTS AND SUM OF RIGHT DIAGONAL

ELEMENTS
#include<stdio.h>
int main()
{
int mat[5][5],sumleft=0,sumright=0;
int i,j;
printf("Enter the values\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&mat[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d\t",mat[i][j]);
printf("\n");
}
printf("The sum of left diagonal elements of a matrix is\n");
for(i=2,j=2;i>=0;i--,j--)
sumleft+=mat[i][j];
printf("%d\t",sumleft);
printf("\nThe sum of right diagonal elements of a matrix is \n");
for(i=0,j=2;j>=0;i++,j--)
sumright+=mat[i][j];
printf("%d\t",sumright);
return 0;
}
SUM OF ROW ELEMENTS IN A MATRIX
#include<stdio.h>
int main()
{

int mat[5][6];
int i,j;
printf("Enter the values\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
scanf("%d",&mat[i][j]);
}
printf("The matrix is\n");
for(i=0;i<3;i++) {
for(j=0;j<4;j++)
printf("%d\t",mat[i][j]);
printf("\n");
}
printf("The result is\n");
for(i=0;i<3;i++)
{
int sum=0;
for(j=0;j<4;j++) {

printf("%d\t",mat[i][j]);
sum+=mat[i][j];
}
printf("the sum is %d\n",sum);
}
return 0;

//SUM OF TWO MATRICES

#include<stdio.h>
int main()
{
int mat1[5][6],mat2[5][6],sum[5][6];
int i,j;
printf("Enter the values\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
scanf("%d",&mat1[i][j]);
}
printf("matrix of the values\n");
for(i=0;i<3;i++) {
for(j=0;j<4;j++)
printf("%d\t",mat1[i][j]);
printf("\n");
}
printf("Enter the values\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
scanf("%d",&mat2[i][j]);
}
printf("matrix of the values\n");
for(i=0;i<3;i++) {
for(j=0;j<4;j++)
printf("%d\t",mat2[i][j]);
printf("\n");
}
printf("The sum of the two matrices are\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
sum[i][j]=mat1[i][j]+mat2[i][j];
printf("%d\t",sum[i][j]);
}
printf("\n");
}
return 0;
}

//DETERMINING MINIMUM AND MAXIMUM VALUES IN A MATRIX


#include<stdio.h>
int main()
{
int mat[5][6];
int i,j,min,max,m,n;
printf("Enter the row and column size\n");
scanf("%d%d", &m,&n);
printf("Enter the matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&mat[i][j]);
}
printf("The matrix is \n");
for(i=0;i<m;i++) {
for(j=0;j<n;j++)
printf("%d\t",mat[i][j]);
printf("\n");
}
min=max=mat[0][0];
for(i=0;i<m;i++) {
for(j=0;j<n;j++)
{
if(mat[i][j]>max)
max=mat[i][j];
if(mat[i][j]<min)
min=mat[i][j];
}
}
printf("the minimum is %d",min);
printf("\nthe maximum is %d", max);
return 0;
}

TRANSPOSE OF A MATRIX
#include<stdio.h>
int main()
{
int mat[5][6];
int i,j;
printf("Enter the matrix values\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
scanf("%d",&mat[i][j]);
}
printf("The matrix is\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",mat[i][j]);
}
printf("\n");
}
printf("The transpose of matrix is\n");
for(j=0;j<4;j++)
{
for(i=0;i<3;i++)
{
printf("%d\t",mat[i][j]);
}
printf("\n");
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy