Advertisement Remove all ads

Define Structure Consisting of Following Elements 1. Student Roll_No 2. Student Name 3. Student Percentage Write a Program to Read Records of 5 Students of and Display Same. - Structured Programming Approach

Define structure consisting of following elements
1. student roll_no
2. student name
3. student percentage
Write a program to read records of 5 students of and display same.

Advertisement Remove all ads

Solution

• The Structure for above given elements can be defined as : 

struct student
{
char stud_name[20];
int roll_no;
int percentage;
};
Program:
#include<conio.h>
#include<stdio.h>
struct student
{
char stud_name[20];
int roll_no;
int percentage;
};
void main ()
{
struct student st[100];
int n,i,j;
clrscr();
for(i=0;i<=4;i++)
{
printf("Enter the student's name, roll number and percentage:");
scanf("%s %d %d" , st[i].stud_name,&st[i].roll_no,&st[i].percentage);
}
printf("Name\tRoll No\tpercentage\n");
printf("----------------------------------------------\n");
for(i=0;i<=4;i++)
{
printf("%s\t%d\t%d\n",st[i].stud_name, st[i].roll_no, st[i].percentage);
}
getch();
}
Output: Enter the student's name, roll number and percentage: ketan
01
90
Enter the student's name, roll number and percentage: carry
02
91
Enter the student's name, roll number and percentage: tom
03
92
Enter the student's name, roll number and percentage: jerry
04
95
Enter the student's name, roll number and percentage: bob
05
96
Name Roll No Percentage
------------------------------------------------------
ketan 01 90
carry 02 91
tom 03 92
jerry 04 95
bob 05 96
  Is there an error in this question or solution?
Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×