I have to make a code to print a square made of stars(*) and its diagonals by inputing the number of lines. For lines=5 it should look like this:square
This is my code so far:
#include <stdio.h>
int main()
{
int i, j, lines;
printf("Enter number of lines:");
scanf("%d",&lines);
for(i=1; i<=lines; i++)
{
for(j=1; j<=lines; j++)
{
if(i==1 || i==lines || j==1 || j==lines)
{
printf("*");
}
else
{
printf(" ");
}
if(i==j)
{
printf(".");
}
if(i==(-j))
{
printf(".");
}
}
printf("\n");
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire