May 28, 2021

C program to display user details using id

EX: Write a C program to display user details using id. How to  write a C program to display user details. C program to display student details using their id.


In this program we will use switch case to print user details.... But you can also do this program using if-else-if statements.


  C program to display user details using id :


#include<stdio.h>

int main()
{
    int id;
    //Accept id from user
    printf("Enter your id: ");
    scanf("%d",&id);
    //Switch the value of id
    switch(id) {
        //Match id with cases
        case 11:
        printf("Information of id %d is:\n",id);
        printf("Name: Omkar Lokhande\nContact: 123456***\nAdd: kalamb");
        break;

        case 12:
        printf("Information of id %d is:\n",id);
        printf("Name: Akash Sutar\nContact: 1234***\nAdd: kalamb");
        break;

        case 13:
        printf("Information of id %d is:\n",id);
        printf("Name: Rusty Shackleford \nContact: 12456***\nAdd: California");
        break;

        default:
        printf("Please Enter Valid Id");   
    }
    return 0;
}
Above program will show the following output:

Enter your id: 13
Information of id 13 is:
Name: Rusty shackleford
Contact: 123456***
Add: California


Share your thoughts in the comment section given below...  :)

No comments:

Post a Comment

If you have any doubts, please discuss here...