Writing a program to print a square of stars without the diagonals was a lengthy process; me, being the cavalier programmer. ;)
This program can easily be done without using the matrix. It's just that I like matrices.
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
#include<stdio.h>
#include<conio.h>
#define MAX 100
int main();
{
int i,j,m,sum=0,arr[MAX][MAX];
printf("Enter the dimensions of the square you want to print: \n");
scanf("%d",&m);
clrscr();
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
sum=i+j;
if(i!=j)
{
if(sum==m-1)
{
arr[i][j]==32;
printf("%c ",arr[i][j]);
}
else
{
arr[i][j]==42;
printf("%c ",arr[i][j]);
}
}
else if(i==j)
{
arr[i][j]==32;
}
}
printf("\n");
}
getch();
return 0;
}
No comments:
Post a Comment