Name :Giridhar Ravsaheb Ghatage
Roll No:670
IMCA-I
#include<stdio.h>
#include<string.h>
//float per,total;
struct student
{
int rno;
char name[50];
float phy,maths,cs;
float per,total;
};
void search_name(struct student [],int);
void search_rno(struct student [],int);
void display(struct student [],int);
void display_greater(struct student [],int,int);
void max_per(struct student [],int);
void modify(struct student [],int );
void main()
{
int n,choice,k,i;
int gt;
printf("Enter number of students:");
scanf("%d",&n);
struct student e[n];
for(i=0;i<n;i++)
{
printf("\nEnter student %d information(rno,name,phy,cs,maths):\n",i+1);
scanf("%d %s %f %f %f",&e[i].rno,e[i].name,&e[i].phy,&e[i].cs,&e[i].maths);
e[i].total=e[i].phy+e[i].cs+e[i].maths;
e[i].per=e[i].total/3;
}
gt:
printf("\[Link] by name\[Link] by rno\[Link] all\[Link] all students having
percentage > something\[Link] student having highest percentage\[Link]\[Link] ");
printf("Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
search_name(e,n);
goto gt;
break;
case 2:
search_rno(e,n);
goto gt;
break;
case 3:
display(e,n);
goto gt;
break;
case 4:
printf("Enter percentage to display student having percentage greater than
that:");
scanf("%d",&k);
display_greater(e,n,k);
goto gt;
break;
case 5:
max_per(e,n);
goto gt;
break;
case 6:
modify(e,n);
goto gt;
break;
case 7:
printf("..Exit..");
default:
printf("Choose case from 1 to 7!!");
goto gt;
break;
}
void search_name(struct student e[],int n)
{
char name1[20];
int i,flag=0;
printf("Enter a name to search:");
scanf("%s",name1);
for(i=0;i<n;i++)
{
if(strcmp(e[i].name,name1)==0)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("Name found\nrno=%d\tname=%s\tPhysics=%f\tCS=%f\tMaths=
%f\tPercentage=%f",e[i].rno,e[i].name,e[i].phy,e[i].cs,e[i].maths,e[i].per);
}
else
{
printf("Not found ");
}
}
void search_rno(struct student e[],int n)
{
int i,num,flag=0;
printf("Enter rno to search:");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(e[i].rno==num)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("Name found\nrno=%d\tname=%s\tPhysics=%f\tCS=%f\tMaths=
%f",e[i].rno,e[i].name,e[i].phy,e[i].cs,e[i].maths);
}
else
{
printf("Rno not found");
}
}
void display(struct student e[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("Info of student %d:\n",i+1);
printf("Name found\nrno=%d\tname=%s\tPhysics=%f\tCS=%f\tMaths=
%f\tPercentage=%f\t",e[i].rno,e[i].name,e[i].phy,e[i].cs,e[i].maths,e[i].per);
}
}
void display_greater(struct student e[],int n, int k)
{
int i;
for(i=0;i<n;i++)
{
if(e[i].per>k)
{
printf("Name found\nrno=%d\tname=%s\tPhysics=%f\tCS=%f\tMaths=
%f\tPercentage=%f",e[i].rno,e[i].name,e[i].phy,e[i].cs,e[i].maths,e[i].per);
}
}
}
void max_per(struct student e[],int n)
{
int i,max,j;
for(i=1;i<n;i++)
{
max=e[i].per;
if(e[i].per>max)
{
max=e[i].per;
j=i;
}
}
printf("Maximum per is %d",max);
//printf("Name found\nrno=%d\tname=%s\tPhysics=%f\tCS=%f\tMaths=
%f",e[i].rno,e[i].name,e[i].phy,e[i].cs,e[i].maths);
}
void modify(struct student e[],int n)
{
int x;
int z;
printf("Enter the roll number"
" to update the entry : ");
scanf("%d", &x);
for (int j = 0; j <=n; j++) {
if (e[j].rno == x)
{
printf("1. Roll No\n"
"2. name\n"
"3. Physics.\n"
"4. CS\n"
"5. Maths\n");
scanf("%d", &z);
switch (z) {
case 1:
printf("Enter the new "
" Roll No : \n");
scanf("%d", &e[j].rno);
break;
case 2:
printf("Enter the new "
" name : \n");
scanf("%s", e[j].name);
break;
case 3:
printf("Enter the new "
"Physics Marks : \n");
scanf("%f", &e[j].phy);
break;
case 4:
printf("Enter the new Cs marks : \n");
scanf("%f", &e[j].cs);
break;
case 5:
printf("Enter the new maths marks \n");
scanf("%f",&e[j].maths);
break;
}
printf("UPDATED SUCCESSFULLY.\n");
}
}
}