//upper left matrix
// code
#include<stdio.h>
#include<conio.h>
main()
{
int i, j, a[20][20], n;
printf("Enter size of matrix: ");
scanf("%d", &n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d", &a[i][j]);
}
}
printf("\n\n The Matrix is\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d", a[i][j]);
}
printf("\n");
}
printf("\n The upper right matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j||j>i)
{
printf("%d", a[i][j]);
}
else
printf(" ");
}
printf("\n");
}
getch();
return 0;
}
// output
Enter the size of matrix:3
Enter the elements:1
2
3
4
5
6
7
8
9
The matrix is:
1 2 3
4 5 6
7 8 9
The upper right matrix is:
1 2 3
5 6
9
No comments:
Post a Comment
Note: only a member of this blog may post a comment.