answersLogoWhite

0


Best Answer

#include <conio.h>

#include <stdio.h>

void main()

{

int a[16][16];

int c=1,i,j,k,m=0,n,x;

clrscr();

printf("Enter the number of rows and columns for the square matrix \n");

scanf("%d",&n);

x=n;

while(n>=1)

{

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

a[m][k+m]=c++;

for(k=1;k<n;k++)

a[k+m][n-1+m]=c++;

for(k=n-2;k>=0;k--)

a[n-1+m][k+m]=c++;

for(k=n-2;k>0;k--)

a[k+m][m]=c++;

n=n-2;

m=m+1;

}

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

{

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

{

printf("%5d",a[i][j]);

}

printf("\n");

}

getch();

}

User Avatar

Wiki User

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

Wiki User

12y ago

#include<stdio.h>

void main()

{

int a[6][6],n,n1,i,sum=0;

printf("Enter the order of the matrix");

scanf("%d %d"'&n,&n1);

if(n==n1)

{

printf("Enter the matrix");

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

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

scanf("%d",&a[i][j]);

printf("The matrix is\n");

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

{

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

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

printf("\n");

}

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

sum+=a[i][i];

printf("Trace of the matrix is=%d",sum);

}

else

printf("Enter a square matrix\n");

}

Other than the fact that the program given will fail for a square matrix which is more than 6x6 (either with odd results or probably a sigsegv) and will fail to compile as a variable is not declared, it now calculates the trace of the given matrix, as calculating the trace requires a square matrix, why ask for both dimensions instead of just asking for the size of the square matrix?

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include

#include

void main()

{

int a[10][10],m,n,i,j,sum=0;

clrscr();

printf("\nEnter number of rows");

scanf("%d",&m);

printf("\nEnter number of columns");

scanf("%d",&n);

if(m==n)

{

printf("Enter values for matrix");

for(i=0;i

{

for(j=0;j

{

printf("\na[%d][%d] value",i,j);

scanf("%d",&a[i][j]);

}

}

printf("\nMatrix\n");

for(i=0;i

{

for(j=0;j

{

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

}

printf("\n");

}

for(i=0;i

{

sum+=a[i][i];

}

printf("\nSum of diagonal elements %d",sum);

}

else

{

printf("\nSORRY!!!SQUARE MATRIX REQUIRED!!!");

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

int main(){

int a[10][10],i,j,sum=0,m,n;

printf("\nEnter the row and column of matrix: ");

scanf("%d %d",&m,&n);

printf("\nEnter the elements of matrix: ");

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

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

scanf("%d",&a[i][j]);

printf("\nThe matrix is\n");

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

printf("\n");

for(j=0;j<m;j++){

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

}

}

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

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

if(i==j)

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

}

}

printf("\n\nSum of the diagonal elements of a matrix is: %d",sum);

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

//program to get numbers from user and print the matrix

#include<stdio.h>

int main()

{

int i,n,j,a[10][10];

printf("\n enter the number of elements ");

scanf("%d",&n);

for(i=0;i<n;i++){

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

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

scanf("%d",&a[i][j]);

}

}

//printing the square matrix

for(i=0;i<n;i++){

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

printf("%4d",a[i][j]);

}

printf("\n");

}

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program on Trace of matrix in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. &lt;&lt;&gt;&gt; The determinant of a singular matix is zero.


What is matrix programming in C programming?

C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion


Write a program to display Identity matrix?

#include &lt;stdio.h&gt; void main() { int a,b,c,i,j; printf("Enter the number of rows for square matrix : "); scanf("%d",&amp;a); for(i=1;i&lt;=a;i++) { for(c=1,j=1;j&lt;=a;j++,c++) { if(c==i) printf("1 "); else printf("0 "); } printf("\n"); } getch(); }


How do you write a c program to analysis a circuit?

There is no need to write a C program for circuit analysis; there are lots of packages out there that already do that (for example, Spice).

Related questions

How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.


Write a c program to find eigenvalue of a matrix?

Yes, do write. That's what you always have to do when you have got a homework-program.


Write a C program to find sum of 3 matrices?

matrix


Write a c program for matrix addition using function?

#include&lt;


Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. &lt;&lt;&gt;&gt; The determinant of a singular matix is zero.


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


Write a c program on reverse the diagonal element of matrix?

mano ni anda yarrr


Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.


What is matrix programming in C programming?

C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion


How do you Write a C program for matrix addition?

for (i=0; i&lt;IMAX; i++) for (j=0; j&lt;JMAX; j++) c[i,j] = a[i,j] + b[i,j];


C Matrix addition program?

How we can addition Two Matrix plz send coding in C language mahesh dhanotiya astah_mahesh@rediff.com how i can built a square matrix in c,