Print diamond on screen with c
#include < stdio.h >
int main()
{
int rows;
printf("Enter the number of rows to print: ");
scanf("%d", &rows);
for(int i = 0; i < rows; i++)
{
for(int j = rows - i ; j >= 0; j--) printf(" ");
printf("*");
//for(int j = 0; j < (i * 2) + 1; j++) printf("*");
for(int j = 0; j < (i * 2) - 1; j++) printf(" ");
if(i > 0) printf("*");
printf("\n");
}
for(int i = rows - 2; i >= 0; i--)
{
for(int j = rows - i; j >= 0; j--) printf(" ");
printf("*");
//for(int j = 0; j < ( i * 2) + 1; j++) printf("*");
for(int j = 0; j < (i * 2) - 1; j++) printf(" ");
if(i > 0) printf("*");
printf("\n");
}
}
Output:
Comments
Post a Comment