Write a program that fills a five-by-five matrix as follows:
#include <stdio.h>
main()
{
int a[10][10],i,j;
clrscr();
printf("This is 5x5 Matrix\n");
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(i+j<=5)
a[i][j]=+1;
else if(i+j>=7)
a[i][j]=-1;
else
a[i][j]=0;
printf("%3d",a[i][j]);
}
putchar('\n');
}
getch();
}
- Upper left triangle with +1s
- Lower right triangle with -1s
- Right to left diagonal with zeros
#include <stdio.h>
main()
{
int a[10][10],i,j;
clrscr();
printf("This is 5x5 Matrix\n");
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(i+j<=5)
a[i][j]=+1;
else if(i+j>=7)
a[i][j]=-1;
else
a[i][j]=0;
printf("%3d",a[i][j]);
}
putchar('\n');
}
getch();
}
No comments:
Post a Comment