C program to Print Heart Star Pattern using For loop

Heart Star Pattern using For loop


Write a C program to Print Heart Star Pattern using For loop. Here’s simple C program to Print Heart Star Pattern using For loop in C Programming Language.


Here is source code of the C program to Print Heart Star Pattern using For loop. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C program to Print Heart Star Pattern using For loop  */

#include <stdio.h>
 
int main()
{
    int i, j, n;
 
    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 : :


/*  C program to Print Heart Star Pattern using For loop  */

Enter value of n : 15

    *******        *******
   *********      *********
  ***********    ***********
 *************  *************
******************************
*****************************
 ***************************
  *************************
   ***********************
    *********************
     *******************
      *****************
       ***************
        *************
         ***********
          *********
           *******
            *****
             ***
              *

Process returned 0

Above is the source code for C program to Print Heart Stars Pattern using For loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

Leave a Reply