C program to print heart star pattern
*** ***
***** *****
**************
*************
***********
*********
*******
*****
***
*
C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)
1238Program:
/** * C program to print heart star pattern * atnyla.com */ #include "stdio.h" int main() { int i, j, n;7 printf("Enter value of n : "); scanf("%d", &n); for(i=n/2; i <= n; i+=2) { for(j=1; j < n-i; j+=2) { printf(" "); } for(j=1; j <= i; j++) { printf("*"); } for(j=1; j <= n-i; j++) { printf(" "); } for(j=1; j <= i; j++) { printf("*"); } printf("\n"); } for(i=n; i >= 1; i--) { for(j=i; j < n; j++) { printf(" "); } for(j=1; j <= (i*2)-1; j++) { printf("*"); } printf("\n"); } return 0; }
Output:
Enter value of n : 7 *** *** ***** ***** ************** ************* *********** ********* ******* ***** *** * Press any key to continue . . .
Explanation:
Required knowledge
Basic C programming, For loop, Nested loop
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.