Write a Program to Display your Name in C
  • Here is the C program to print your own name.
  • Here, we can use the 2 different approaches to print the name:
    1. Using printf()
    2. Using scanf()

C program that uses printf() to print your own name

				
					#include <stdio.h>

int main() {
    printf("My name is [Your Name].\n");
    return 0;
}

				
			
Output

C program that uses scanf() to read your name

				
					#include <stdio.h>

int main() {
    char name[50];

    printf("Enter your name: ");
    scanf("%s", name);

    printf("My name is %s.\n", name);

    return 0;
}

				
			
Output
C Program To Print Your Own Name
  • Using printf(), we display the prompt “Enter your name: “. Then, using scanf(), we read the input entered by the user and store it in the name variable.

  • Finally, we use printf() again to display the entered name as “My name is [Your Name].”

  • When you run this program, it will prompt you to enter your name. After entering your name and pressing Enter, it will display your name on the console.