c code

  • cstructure
  • write a program to store details of 12 student in c

    2. Write a program to read the Roll number, Name, Address, Age & average marks of 12 students in the class and display the details from the function.

    Code

    #include <stdio.h> typedef struct student { int roll_no; int age; int marks; char name[50]; char address[50]; } stu; void display(stu *x, int y) { for (int i = 0; i < y; i++) { printf("\n\n"); printf("name: %s\n", x[i].name); printf("roll_number: %d\n", x[i].roll_no); printf("age: %d\n", x[i].age); printf("marks: %d\n", x[i].marks); printf("address: %s\n", x[i].address); printf("\n\n"); } } void averagemark(stu *x, int y) { float total_marks = 0, avg_marks; for (int i = 0; i < y; i++) { total_marks += x[i].marks; } avg_marks = total_marks / y; printf("average marks : %f", avg_marks); } int main() { int n; printf("enter the no. of students\n"); scanf("%d", &n); stu s1[n]; for (int i = 0; i < n; i++) { printf("enter name\n"); scanf("%s", &s1[i].name); printf("enter roll_number\n"); scanf("%d", &s1[i].roll_no); printf("enter age\n"); scanf("%d", &s1[i].age); printf("enter marks\n"); scanf("%d", &s1[i].marks); getchar(); printf("enter address\n"); scanf("%s", &s1[i].address); getchar(); } display(s1, n); averagemark(s1, n); return 0; }