Home C Programming Language / Programs / C program to print heart star pattern *** *** ***** ***** ************** ************* *********** ********* ******* ***** *** *
🚀 Programming Example

C program to print heart star pattern
  ***    ***
 *****  *****
**************
*************
 ***********
  *********
   *******
    *****
     ***
      *

👁 1,383 Views
💻 Practical Program
📘 Step Learning
Write a C program to print heart star pattern using for loop. How to print heart star pattern in C program. Logic to print heart shape star pattern in C programming.

💻 Program Code

/**
 * 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;
}
                        

🖥 Program Output

Enter value of n : 7
  ***    ***
 *****  *****
**************
*************
 ***********
  *********
   *******
    *****
     ***
      *
Press any key to continue . . .
                            

📘 Explanation

Required knowledge

Basic C programming,?For loop,?Nested loop

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.