answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

int a[3][3],b[3][3],c[3][3],r,c;

for(r=0;r<=3;r++)

{

for(c=0;c<3;c++)

{

printf("\n enter the value=");

scanf("%d%d",&a[r][c],&b[r][c]);

}

}

printf("\n first matrix=\n");

for(r=0;r<=3;r++)

{

for(c=0;c<3;c++)

{

printf("%d\t",a[r][c]);

}

printf("\n");

}

printf("\n scond matrix=\n");

for(r=0;r<=3;r++)

{

for(c=0;c<3;c++)

{printf("%d\t",b[r][c]);

}

printf("\n");

}

printf("\n sum of given matrix=\n");

for(r=0;r<=3;r++)

{

for(c=0;c<3;c++)

{

c[r][c]=a[r][c]+b[r][c];

printf("%d\t",c[r][c]);

}

printf("\n");

}

getch();

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include

void main()

{

int mat[10][10];

int i,j;

int m,n;

int sumrow,sumcol;

cout<<\nenter the order of matrix;

cin>>m>>n;

cout<<\nenter elements of a matrix;

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

cin>>mat[i][j];

}

for(i=0;i<m;i++)

{

sumrow=0;

for(j=0;j<n;j++)

sumrow=sumrow+mat[i][j];

cout<<"\n the sum of"<<i<<"row="<<sumrow;

}

for(j=0;j<n;j++)

{

sumcol=0;

for(i=0;i<m;i++)

sumcol=sumcol+mat[i][j];

cout<<\nthe sum of"<<j<<"column="<<sumcol;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include <stdio.h>

main()

{

int a[5][5];

for (int i=0;i<5;i++)

{

for(int j=0;j<5;j++)

{

a[i][j]=10+j+i;

}

}

for (int i=0;i<5;i++)

{

printf("%d\n",a[i][i]);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

void main() { int arr1[3][3],arr2[3][3];
int i,j;
for(i=0;i<3;i++) //insertion of element of first array
{ for(j=0;j<3;j++)
{ scanf("%d",&arr1[i][j]);
}
}
for(i=0;i<3;i++) //elements of second array
{ for(j=0;j<3;j++)
{ scanf("%d",&arr2[i][j]);
}
}
for(i=0;i<3;i++) //addition
{ for(j=0;j<3;j++)
{ arr3[i][j]=arr1[i][j]+arr2[i][j];
}
}
for(i=0;i<3;i++) //output show
{ for(j=0;j<3;j++)
{ printf("%d",&arr[i][j]);
}
}
getch();
}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include

#include

int main()

{

clrscr();

int A[10][10],m,n,x,y,sum=0;

//Create a Matrix A

cout << "Enter number of rows and columns in Matrix A : \n";

cin>>n>>m;

cout << "Enter elements of Matrix A : \n";

for(x=1;x

for(y=1;y

cin>>A[x][y];

//Find sum of each row

for(x=1;x

{

A[x][m+1]=0;

for(y=1;y

A[x][m+1]=A[x][m+1]+A[x][y];

}

//Find sum of each column

for(y=1;y

{

A[n+1][y]=0;

for(x=1;x

A[n+1][y]+=A[x][y];

}

cout << "\nMatrix A, Row Sum (Last Column)" << " and Column Sum (Last Row) :\n";

for(x=1;x

{

for(y=1;y

cout << A[x][y] << " ";

cout << "\n";

}

//Print sum of each column

x=n+1;

for(y=1;y

cout << A[x][y] << " ";

cout << "\n";

if(m==n)

{

for(x=1;x

for(y=1;y

if(x==y) sum+=A[x][y];

else if(y==m-(x+1)) sum+=A[x][y];

}

cout << "Sum of diagonal elements is : " << sum << endl;

getch();

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include

#include

int main()

{

clrscr();

int A[10][10],m,n,x,y,sum=0;

//Create a Matrix A

cout << "Enter number of rows and columns in Matrix A : \n";

cin>>n>>m;

cout << "Enter elements of Matrix A : \n";

for(x=1;x

for(y=1;y

cin>>A[x][y];

//Find sum of each row

for(x=1;x

{

A[x][m+1]=0;

for(y=1;y

A[x][m+1]=A[x][m+1]+A[x][y];

}

//Find sum of each column

for(y=1;y

{

A[n+1][y]=0;

for(x=1;x

A[n+1][y]+=A[x][y];

}

cout << "\nMatrix A, Row Sum (Last Column)" << " and Column Sum (Last Row) : \n";

for(x=1;x

{

for(y=1;y

cout << A[x][y] << " "; cout << "\n"; }

//Print sum of each column x=n+1;

for(y=1;y

cout << A[x][y] << " "; cout << "\n";

if(m==n)

{

for(x=1;x

for(y=1;y

if(x==y) sum+=A[x][y];

else if(y==m-(x+1)) sum+=A[x][y];

}

cout << "Sum of diagonal elements is : " << sum << endl;

getch();

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

To find the sum of the diagonals of a given matrix the following code fragment can be used (with suitable definitions and data initialisations):

if (num_rows > num_cols) max = num_cols;

else max = num_rows;

sum = 0;

for (i = 0; i < max; i++) sum += matrix[i][i];

printf("Sum of diagonal elements is %d\n", sum);

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include

int main()

{

int a,b,c;

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Yes, please do.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C program to print the diagonal element of a NxN matrix?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to print the sum of a sparse matrix?

This is a directive, not a question.


Write a program using iostreams to take as input two multi-dimensional arrays and print their sum as output Matrix Addition in Matrix format?

http://www.assignmentsclub.com/


How do you erase dot matrix print from paper?

how do you erase dot matrix print form paper


What is the highest quality of print produced by a dot matrix?

A basic dot matrix has 9 pins, which produces an average print. A dot matrix with 24 pins (or more) will produce a better quality print.


Printer has a print head that moves across the width of the paper using pins to print a matrix of dots on the page?

dot matrix


C program to print helical matrix?

//the following code will help you to write the program for(i=n-1, j=0; i &gt; 0; i--, j++) //n is the order of the square matrix { for(k=j; k &lt; i; k++) printf("%d ", a[j][k]); for(k=j; k &lt; i; k++) printf("%d ", a[k][i]); for(k=i; k &gt; j; k--) printf("%d ", a[i][k]); for(k=i; k &gt; j; k--) printf("%d ", a[k][j]); } m= (n-1)/2; //calculate the position of the middle element if (n% 2 == 1) printf("%d", a[m][m]);//to print the middle element also //9809752937(udanesh)


Is it possible to print matrix without using array?

Yes but why.


Write a C program to accept the elements of a 3 x 3 matrix and find its sum of the major diagonal elements The program should print the given matrix along with its sum of the major diagonal elements?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; void main() { int d[3][3] = { 1, 2, 6, 3, 8, 5, 5, 6, 7 }; int k = 0, j = 0; int sum1 = 0, sum2 = 0; for (j = 0; j &lt; 3; j++) { for (k = 0; k &lt; 3; k++) printf(" %3d", d[j][k]); printf("\n"); } for (j = 0; j &lt; 3; j++) { sum1 = sum1 + d[j][j]; } k = 3 - 1; for (j = 0; j &lt; 3; j++) { if (k &gt;= 0) { sum2 = sum2 + d[j][k]; k--; } } printf("Sum of First diagonal= %d\n", sum1); printf("Sum of Second diagonal= %d", sum2); getch();


Differentiate line and dot matrix printer?

A line printer and dot matrix printer differ in how they print pages. Line printers are more commonly used with computers, while dot matrix printers function similarly to a typewriter.PrintingA line printer print pages exactly as its name implies, one line at a time. Dot matrix printers use pins arranged in a matrix that physically strike an ink ribbon between the pin and the paper to print characters.SpeedLine matrix printers can print roughly 1,200 lines per minute, or generally about 20 pages per minute. Dot matrix printers print about 40-300 characters per second, or about six to seven pager per minute, at best.QualityDot matrix printers have a lower print quality than line printers. The characters' shapes on pages printed using a dot matrix printer appear as a number of dots connected together. Line printers print solid characters and can use a wide variety of font face and sizes.


Write a unix program to print print a pattern?

echo 'print a pattern'


Write a java program to print the result in the series?

If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).


Write an assembly language program to print a to z on screen?

write a program to print A to Z on screen in c?