Problem Description
1 Create a structure "student".
2. This structure has three members: name (string), roll (integer) and marks (float).
3. Created a structure array of size 3 to store information of 3 students and structure variable as "s".
Hint: s[3];
4. Using for loop, the program takes the information of 3 students from the user and displays it on the screen.CODING ARENA
#include <stdio.h>
struct student
{
char name[10];
int roll;
float marks;
}s[3];
int main()
{
int i;
for(i=0;i<3;i++)
{
s[i].roll=i+1;
scanf("%s",s[i].name);
scanf("%f",&s[i].marks);
}
for(i=0;i<3;i++)
{
printf("Roll number=%d\n",i+1);
printf("Name=%s\n",s[i].name);
printf("Marks=%.2f\n",s[i].marks);
}
return 0;
}
Test Case 1
Input (stdin)Bogar 99.33 Siddhar 99.44 Tamil 99.99
Expected OutputRoll number=1 Name=Bogar Marks=99.33 Roll number=2 Name=Siddhar Marks=99.44 Roll number=3 Name=Tamil Marks=99.99
Test Case 2
Input (stdin)Tom 98.22 Bob 65.12 Alice 45.43
Expected OutputRoll number=1 Name=Tom Marks=98.22 Roll number=2 Name=Bob Marks=65.12 Roll number=3 Name=Alice Marks=45.43
No comments:
Post a Comment