write an program in c++ to input and print name and roll no.of 5 student through thu use of array of object
Answers
Answered by
5
Answer:
#include
struct student
{
char name[50];
int roll;
float marks;
} s[100];
int main()
{
int i,n,rn,k;
struct student s[100];
printf("Enter total of students:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter information of student %d:\n",i+1);
printf("Enter name: ");
scanf("%s", s[i].name);
printf("Enter roll number: ");
scanf("%d", &s[i].roll);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Inter Roll number to search student record:\n");
scanf("%d",&rn);
for(i=0;i<n;i++)
{
if(s[i].roll==rn)
{
k=i;//for finding position of student
printf("\n Record found at position no %d \n",k+1);
printf("\tName:%s\n ",s[k].name);
printf("\t Roll number: %d\n",s[k].roll);
printf("\t Marks: %.1f\n\n",s[k].marks);
}
}
return 0;
}
Similar questions
Science,
5 months ago
Accountancy,
5 months ago
Social Sciences,
5 months ago
Math,
10 months ago
Chemistry,
1 year ago
Physics,
1 year ago