Call us at 0700-922-6559 or Click here

Write a program to create Student I-Card using a Structure.

Below is the program to create Student I-Card using a Structure in C Programming with step-by-step explanation.

#include<stdio.h>

struct student {
char name[50];
int rollno;
char branch[20];
};

int main() {
struct student s;

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

printf("Enter roll number: ");
scanf("%d", &s.rollno);

printf("Enter branch: ");
scanf("%s", s.branch);

printf("\nStudent I-Card\n");
printf("Name: %s\n", s.name);
printf("Roll Number: %d\n", s.rollno);
printf("Branch: %s\n", s.branch);

return 0;

}

Output-

Enter name: Sunita
Enter roll number: 1
Enter branch: IT

Student I-Card
Name: Sunita
Roll Number: 1
Branch: IT

Following is the Step-by-step explanation of the program:

  1. Firstly, we need to include the standard input-output library <stdio.h> which contains the functions for input and output operations.
  2. Then, we declare a struct named student which covered three members such as – name (string), rollno (integer), and branch (string). This structure will be used to store the student details.
  3. In the main() function, we declare a variable s of type struct student which will store the details of a single student.
  4. We use the printf() function to prompt the user to enter the student’s name, roll number, and branch.
  5. We use the scanf() function to read the user input and store it in the corresponding members of the s structure.
  6. Then we print the details of the student using the printf() function.
  7. Finally, we return 0 to indicate successful completion of the program.

The program prompts the user to enter the student’s details, which are then stored in the struct s. Then, the program prints the details of the student in a formatted manner. This program demonstrates the use of a struct to store related data and retrieve it later.

Once you have written the code, you can compile and run it using a C compiler, such as GCC, on your computer. The program will then display output on the screen when executed.

For more information about C programming join our course of C programming.

Leave a Reply

Your email address will not be published. Required fields are marked *