C Program to Print Number Heart Pattern

Ex:  Write a C program to print number heart pattern, which shows the steps to print pattern. How to write a C program to print number heart pattern, which shows steps to print pattern . C program to print number heart pattern which shows steps to print pattern.



Input from user:

Enter the number: 5


Expected output:

  11      22

1111  2222

333333333

  3333333

    33333

      333

        3



This pattern is same as previous exercises star heart pattern.


Only difference is:

In this pattern we only need to replace the * with numbers 1, 2 and 3

This number's also shows the steps to print this pattern.



  Program to print number heart pattern:


#include<stdio.h>

void main()

{

int no,z;

int i,j,k;

printf("Enter the number:\n");

scanf("%d",&no);

/*To print upper part*/

z=no*2;

for(i=no/2;i<=no;i=i+2)

{

/*To print left peak */

for(j=1;j<no-i;j=j+2)

{

                    printf(" ");

}

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

{

                   printf("1");

}

/*To print right peak*/

for(j=1;j<=no-i;j++)

{

    printf(" ");

}

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

{

printf("2");

}

printf("\n");

}

/*To print lower part means inverted triangle*/

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

{

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

{

printf(" ");

}

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

{

printf("3");

}

z-=2;

printf("\n");

}

}



Above program shows the following output:


C Program to Print Number Heart Pattern



No comments:

Post a Comment

If you have any doubts, please discuss here...👇