A structure is used in C to group different types of data under a single name. It helps to store related information together. In this program, a structure named student is created to store student details such as name, roll number, and fees.
The structure variable s is used to access structure members. The program accepts student details from the user and displays all stored information.
How It Works?
student with members name, rollno, and fees.s.#include <stdio.h> #include <conio.h> struct student { char name[20]; int rollno, fees; }; main() { struct student s; clrscr(); printf("Enter the Name : "); scanf("%s", s.name); printf("\nEnter Roll No. : "); scanf("%d", &s.rollno); printf("\nEnter the Fees : "); scanf("%d", &s.fees); printf("\nStudent Name is %s", s.name); printf("\nRoll No. of the student is %d", s.rollno); printf("\nFees of the Student is %d", s.fees); getch(); }
structure to store and display employee details such as employee name, employee id, and salary.employee with members name, id, and salary. Create a structure variable, accept employee details from the user, and display all information.
#include <stdio.h> #include <conio.h> struct employee { char name[20]; int id, salary; }; main() { struct employee e; clrscr(); printf("Enter Employee Name : "); scanf("%s", e.name); printf("\nEnter Employee ID : "); scanf("%d", &e.id); printf("\nEnter Salary : "); scanf("%d", &e.salary); printf("\nEmployee Name is %s", e.name); printf("\nEmployee ID is %d", e.id); printf("\nEmployee Salary is %d", e.salary); getch(); }
employee to store employee information. The structure variable e stores the employee name, ID, and salary. After accepting values from the user, the program displays all employee details.