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:
- The
#include <stdio.h>statement is a preprocessor directive that includes the standard input/output library. - The
int main()function is the starting point of the program. It returns an integer value and contains the program’s instructions. - Inside the
main()function, we declare a character arraynameof size 25, which is used to store the inputted name. - The
printf()function displays a message to the user, prompting them to enter their name. - The
scanf()function reads the user input from the keyboard and stores it in thenamearray. - Finally, the second
printf()function displays a welcome message to the user, using the inputted name. - 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.