Friday, 30 December 2011

C program to find the upper right and lower left triangles of a matrix



#include<stdio.h>
main()
{
int a[10][10],i,j,r,c;
printf("Enter the order of the matrix\n");
scanf("%d%d",&r,&c);
printf("Enter the values\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nThe matrix is\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
if(r==c)
{
printf("\nUpper right triangle\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(j>=i)
printf("%d\t",a[i][j]);
else
printf("\t");
}
printf("\n");
}
printf("\nLower left triangle\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(j<=i)
printf("%d\t",a[i][j]);
}
printf("\n");
}
}
else
printf("\nNot possible to print triangles");
printf("\n");
}




You Like It!? Then kindly share with your Friends.
Comments
0 Comments

No comments:

Post a Comment