Open In App

C Program To Print Your Own Name

Last Updated : 18 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Here, we can use the 2 different approaches to print the name:

  1. Using printf()
  2. Using scanf()

Input: 

Enter Name = Mukul

Output: 

Name = Mukul

Example 1: In this example, we print the user name using printf() function.

C
// C program to demonstrate printing of
// our own name using printf()
#include <stdio.h>

int main()
{
    // print name
    printf("Name : GeeksforGeeks");
    return 0;
}

Output
Name : GeeksforGeeks

Example 2: In this example, we use scanf() to accept the name as input from the user and then print it.

C
// C program to demonstrate printing of
// our own name using scanf()
#include <stdio.h>

int main()
{
    char name[20];
    printf("Enter name: ");

    // user input will be taken here
    scanf("%s", name);
    printf("Your name is %s.", name);
    return 0;
}

Output:

Enter name: Mukul
Your name is Mukul.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads