Call us at 0700-922-6559 or Click here

Write a program to print message with an inputted name.

Below is a program to print message with an inputted name with explanation in C language.

#include < stdio.h >

int main( )
{
char name[25] ;
printf(” Enter your name : “) ;
scanf(“%s”,name) ;
printf(“\n Hello !!: %s”,name) ;
return 0 ;
}

Output –

Enter your name : jiwanjot

Hello !!: jiwanjot

Here’s a step-by-step explanation of the program:

  1. The #include <stdio.h> statement is a preprocessor directive that includes the standard input/output library.
  2. The int main() function is the starting point of the program. It returns an integer value and contains the program’s instructions.
  3. Inside the main() function, we declare a character array name of size 25, which is used to store the inputted name.
  4. The printf() function displays a message to the user, prompting them to enter their name.
  5. The scanf() function reads the user input from the keyboard and stores it in the name array.
  6. Finally, the second printf() function displays a welcome message to the user, using the inputted name.
  7. The return 0; statement indicates that the program has finished executing.

To run the program, compile and execute it using a C compiler, such as GCC.

If you want to more information about C programming, then join our course.

Leave a Reply

Your email address will not be published. Required fields are marked *