Implement structures to read, write, and compute average-marks and the students scoring above and below the average marks for a class of N students.

All QuestionsCategory: C LanguageImplement structures to read, write, and compute average-marks and the students scoring above and below the average marks for a class of N students.
nikhil.d asked 3 years ago
2 Answers
nikhil.d answered 3 years ago

#include <stdio.h>
#include <stdlib.h>
typedef struct
{
    char name[20];
    int usn;
    int marks;
} stud;
int main()
{
    int i, n;
    float avg = 0;
    stud st[50];
    printf(“enter the number of students\n”);
    scanf(“%d”, &n);
    printf(“enter the student details\n”);
    for (i = 0; i < n; i++)
    {
        printf(“\n name:”);
        scanf(“%s”, st[i].name);
        printf(“\n usn:”);
        scanf(“%d”, &st[i].usn);
        printf(“\n marks:”);
        scanf(“%d”, &st[i].marks);
        avg = avg + st[i].marks;
    }
    avg = avg / n;
    for (i = 0; i < n; i++)
    {
        printf(“\n name \t %s”, st[i].name);
        printf(“\n usn \t %d”, st[i].usn);
        printf(“\n marks\t:%d\n”, st[i].marks);
        if (st[i].marks < avg)
            printf(“the student is below the average\n”);
        else
            printf(“the student is above average\n”);
    }
}

Anonymous answered 3 years ago

Note: Change the double inverted comma ( ” ) in the code to avoid an error.