C Program to Print a Smiling Face on Screen

This post was written and published in order to provide the C program code and its description for printing a happy or smiling face on the output console. So let's begin now without further ado.

To print a smiling face on the screen in C programming, use the ASCII value of smiling face, which is 1.

The following C program prints the smiling face on the output console using the ASCII value of the smiling face.

#include<stdio.h>
#include<conio.h>

int main()
{
   int happyASCII = 1;

   printf("%c", happyASCII);

   getch();
   return 0;
}

This C program was built and run in the Code::Blocks IDE. The output of the above C program is shown in the following screenshot:

c program print happy face

I used the red arrow to draw your attention to the smiley emoji printed on the output console.

The "%c" format specifier in C is used when we need to format the value to a character, so using "%c" as the format specifier of "happyASCII," which is an integer type value, converts to a character. And since the character that represents the ASCII value 1 is a smiley emoji, we have already seen the output that was shown in the previous snapshot.

The above program can also be written as:

#include<stdio.h>
int main()
{
   printf("%c", 1);
   return 0;
}

Or,

#include<stdio.h>
int main()
{
   int i = 1;
   char ch = i;
   printf("%c", ch);
   return 0;
}

You will get the same output as the output produced by the first program in this post.

Now let's create another program that allows the user to enter the number to print the smiley faces for the desired number. The following C program asks the user to enter the number of smiling faces he or she wants to print on the screen, to print the required number of smiling faces on the screen:

#include<stdio.h>
#include<conio.h>
int main()
{
   int sml=1, i, limit;
   printf("How many smiley faces do you want to print? ");
   scanf("%d", &limit);
   for(i=0; i<limit; i++)
   {
      printf("%c ", sml);
   }
   printf("\n");
   getch();
   return 0;
}

When the above C program is compiled and executed, it will produce the following result: This output was produced after I typed 50 and hit the ENTER key.

c program print smiling face

You can also format the output screen of the smiling face as per your requirements.

The same program in other language:

C Quiz


« Previous Program Next Program »


Liked this post? Share it!