Sunday, 24 April 2022

7. Create a structure student with rollno (int), name (char array), marks (int), grade (char). Create an array stu[5] of type student. Take the details of students like rollno, name, and marks from the user. Call UDF prepare_result() which will store the values for grade based on marks (if marks >=75 then ‘A’, Between 60 to 75 ‘B’, Between 50 to 60 ‘C’, Between 35 to 50 ‘D’ and Below 35 ‘F’ grade). Print the details of the students with Grade.

 



#include<stdio.h>
#include<conio.h>

struct student
{
    int rollno,marks;
    char name[30],grade;
}stu[5];

void prepare_result();
void main()
{
    int i;
    clrscr();

    for(i=0; i<5; i++)
    {
        printf("\nenter %d student roll no: ",i+1);
        scanf("%d",&stu[i].rollno);
        printf("enter %d student name: ",i+1);
        scanf("%s",&stu[i].name);
        printf("enter %d student marks: ",i+1);
        scanf("%d",&stu[i].marks);
    }

    prepare_result();
    getch();
}

void prepare_result()
{
    int i;
    for(i=0; i<5; i++)
    {
        if(stu[i].marks >= 75)
        {
            stu[i].grade = 'A';
        }
        else if(stu[i].marks >= 60)
        {
            stu[i].grade = 'B';
        }
        else if(stu[i].marks >= 50)
        {
            stu[i].grade = 'C';
        }
        else if(stu[i].marks >= 35)
        {
            stu[i].grade = 'D';
        }
        else
        {
            stu[i].grade = 'F';
        }
    }

    printf("\n\n         !!  result !!         ");
      printf("\n===============================");
    for(i=0; i<5; i++)
    {
        printf("\n%d   %10s  %d   %c",stu[i].rollno,stu[i].name,
                                      stu[i].marks,stu[i].grade);
    }
    printf("\n===============================");
}

/*      output:

enter 1 student rolll no: 1
enter 1 student name: vrushal
enter 1 student marks: 39

enter 2 student roll no: 2
enter 2 student name: smit
enter 2 student marks: 80

enter 3 student roll no: 3
enter 3 student name: vaibhav
enter 3 student marks: 49

enter 4 student roll no: 4
enter 4 student name: anuj
enter 4 student marks: 60

enter 5 student roll no: 5
enter 5 student name: arshad
enter 5 student marks: 80


         !!  result !!
===============================
1      vrushal  39   D
2         smit  80   A
3      vaibhav  49   D
4         anuj  60   B
5       arshad  80   A
===============================

*/

No comments:

Post a Comment

python programs

1. sum of two number