Store and Display Student Details Using Structure
#include <stdio.h>
// Create structure for student
struct Student {
char name[50];
int roll;
char address[100];
char course[10];
};
int main() {
struct Student s[10];
int i;
// Get student details
for(i = 0; i < 10; i++) {
printf("\nEnter details of student %d:\n", i + 1);
printf("Name: ");
scanf(" %[^\n]", s[i].name);
printf("Roll Number: ");
scanf("%d", &s[i].roll);
printf("Address: ");
scanf(" %[^\n]", s[i].address);
printf("Course (BCA/MCA): ");
scanf(" %[^\n]", s[i].course);
}
// Show student details
printf("\n--- Student Details ---\n");
for(i = 0; i < 10; i++) {
printf("\nStudent %d\n", i + 1);
printf("Name : %s\n", s[i].name);
printf("Roll : %d\n", s[i].roll);
printf("Address: %s\n", s[i].address);
printf("Course : %s\n", s[i].course);
}
return 0;
}
0 टिप्पणियाँ:
Post a Comment