How to create a program using c language which will store information about students and you can add another students after also and you will be able to search student by his/her roll no.?
ANS:- Here is the code
(Tip:- Make sure to compile this code and do practice a lot to gain knowledge about programming )
#include<stdio.h>
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
int i,num,n,choice,flag,j,p,z,ch,r=0,c;
struct student s[50];
do
{
printf("enter the process 1:ADD 2:diplay 3:search ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter no of student\n");
scanf("%d",&z);
r=r+z;
p=r;
printf("enter info\n");
for(i=0;i<p;i++)
{
printf("enter name\n");
scanf("%s",s[i].name);
printf("enter roll no\n");
scanf("%d",&s[i].roll);
printf("enter marks\n");
scanf("%f",&s[i].marks);
}
break;
case 2 :
printf("displaying info\n");
for(i=0;i<p;i++)
{
printf("\n name %s \n",s[i].name);
printf("\n roll %d \n",s[i].roll);
printf("\n marks %f \n",s[i].marks);
}
break;
case 3:
printf("searching info\n");
printf("enter no\n");
scanf("%d",&num);
for(i=0;i<p;i++)
{
if(num == s[i].roll)
{
printf("\n name %s \n",s[i].name);
printf("\n roll %d \n",s[i].roll);
printf("\n marks %f \n",s[i].marks);
}
else
{
printf("record not found\n");
}
}
break;
}
printf("Do you want to continue 1-yes 2-no");
scanf(" %d",&c);
}while(c==1);
printf("exit \n");
return 0;
}
used content :-
- c language
- do - while loop
- for loop
- main function
- if else statements
Comments
Post a Comment