C program to print name, birthday and city

Write a C program that will print your personal information

In this tutorial, we will learn how to format and display personal information inside the console using C programming. To solve this problem we will use the printf function to display hardcoded user information. Fortunately, we will see two methods here.

The first one is simply displaying the user information directly after the console program runs immediately. And in the second method, we will add some features. That is when the program starts it will ask the user information and then after taking all the information the input value will show up.

C program to print name, birthday and city

#include <stdio.h>
int main() {
    printf("Name: Mehrab Mohul\n");
    printf("Birthday: December 28, 1998\n");
    printf("City: Toronto, Canada\n");
    return 0;
}
Sample InputSample Output
No InputYour name: Mehrab Mohul
Your Birthday: 28 Dec 1998
Your City: Jhenaidah

Business logic

Here we just used the C built-in printf function to display the user information as text data.

By taking Input:

#include <stdio.h>
int main() {
    char name[20], birthday[30], city[50];

    printf("Enter your personal information: \n");
    printf("Enter your name: ");
    gets(name);
    printf("Enter your birthday: ");
    gets(birthday);
    printf("Enter your city: ");
    gets(city);

    printf("\n\nYour information is:\n");
    printf("Your name: %s\n", name);
    printf("Your Birthday: %s\n", birthday);
    printf("Your City: %s\n", city);

    return 0;
}
Sample InputSample Output
Enter your personal information:
Enter your name: Mehrab Mohul
Enter your birthday: 28 Dec 1998
Enter your city: Jhenaidah
Your information is:
Your name: Mehrab Mohul
Your Birthday: 28 Dec 1998
Your City: Jhenaidah

Business logic

In the above example, inside the main function, we declared three character arrays for storing name, birthday, and city. Then we gradually take input using the gets function. And printf for displaying the metadata and actual variable data.

Posted in