#include<stdio.h>
#include<conio.h>
int main(){
int i, j, a[20][20], size;
printf("Enter size of matrix: ");
scanf("%d", &size);
printf("Enter the elements\n");
for(i=0;i<size;i++){
for(j=0;j<size;j++){
scanf("%d", &a[i][j]);
}
}
printf("\n\n The Matrix is\n");
for(i=0;i<size;i++){
for(j=0;j<size;j++){
printf("%d", a[i][j]);
}
printf("\n");
}
printf("\n The Sparse Matrix\n");
for(i=0;i<size;i++){
for(j=0;j<size;j++){
if((i+j)>=(size-1)){
printf("%d", a[i][j]);
}
else
printf(" ");
}
printf("\n");
}
getch();
return 0;
}
Output:
Enter size of matrix: 3
Enter the elements
1 2 3 4 5 6 7 8 9
The Matrix is
123
456
789
The Sparse Matrix
3
56
789
4.5/5 well done!
ReplyDeletethanks Bandana
ReplyDelete