Wednesday, 5 July 2017

C program to print Heart star pattern on screen


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h> 
   
int main() { 
    int i,j, rows;
     
    printf("Enter the number of rows\n");
    scanf("%d", &rows); 
    /* printing top semi circular shapes of heart */
    for(i = rows/2; i <= rows; i+=2){
     /* Printing Spaces */
        for(j = 1; j < rows-i; j+=2) { 
            printf(" "); 
        }
        /* printing stars for left semi circle */
        for(j = 1; j <= i; j++){ 
            printf("*"); 
        
        /* Printing Spaces */
        for(j = 1; j <= rows-i; j++){ 
            printf(" "); 
        
        /* printing stars for right semi circle */
        for(j = 1; j <= i; j++){ 
            printf("*"); 
        
        /* move to next row */
        printf("\n"); 
    
     
    /* printing inverted start pyramid */
    for(i = rows; i >= 1; i--){ 
        for(j = i; j < rows; j++){ 
            printf(" "); 
        
        for(j = 1; j <= (i*2)-1; j++){ 
            printf("*"); 
        
        /* move to next row */
        printf("\n"); 
    
   
    return 0; 
Output
Enter the number of rows
7
 **   **
**** ****
*********
 *******
  *****
   ***
    *

No comments:

Post a Comment