100% found this document useful (1 vote)
365 views

C Program To Print Diamond Pattern

This C program takes a number of rows from the user as input and prints a diamond pattern of asterisks of that height, with a single asterisk at the top and bottom points and the widest section in the middle, using nested for loops to control the number of spaces and asterisks printed on each line.

Uploaded by

haldersubhas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
365 views

C Program To Print Diamond Pattern

This C program takes a number of rows from the user as input and prints a diamond pattern of asterisks of that height, with a single asterisk at the top and bottom points and the widest section in the middle, using nested for loops to control the number of spaces and asterisks printed on each line.

Uploaded by

haldersubhas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

* C Program to Print Diamond Pattern


Enter number of rows
5
*
***
*****
*******
*********
*******
*****
***
*
*/

#include <stdio.h>

int main()

int number, i, k, count = 1;

printf("Enter number of rows\n");

scanf("%d", &number);

count = number - 1;

for (k = 1; k <= number; k++)

for (i = 1; i <= count; i++)

printf(" ");

count--;

for (i = 1; i <= 2 * k - 1; i++)

printf("*");
printf("\n");

count = 1;

for (k = 1; k <= number - 1; k++)

for (i = 1; i <= count; i++)

printf(" ");

count++;

for (i = 1 ; i <= 2 *(number - k)- 1; i++)

printf("*");

printf("\n");

return 0;

You might also like