Problem
Create a structure to specify data on students given below:- Roll number
- Name
- Department
- Course
- Year of joining
Solution - Code
#include<stdio.h>#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct book
{
int roll;
char name[20];
char department[20];
char course[20];
int year;
}b[2];
int main ()
{
int i;
for (i=0;i<2;i++)
{
printf ("Enter roll no. : ");
scanf ("%d",&b[i].roll);
fflush (stdin);
printf ("Enter name: ");
gets (b[i].name);
fflush (stdin);
printf ("Enter department: ");
gets (b[i].department);
fflush (stdin);
printf ("Enter course: ");
gets (b[i].course);
printf ("Enter year: ");
scanf ("%d",&b[i].year);
}
for (i=0;i<2;i++)
printf("\n\nRoll number: %d\nName: %s\nDepartment: %s\nCourse: %s\nYear: %d\n",b[i].roll,b[i].name,b[i].department,b[i].course,b[i].year);
printf ("\npress any key to close.");
getch();
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.