Sunday, September 14, 2014

Create a structure that stores student data and then display it


Problem

Create a structure to specify data on students given below:
  • Roll number
  • Name
  • Department
  • Course
  • Year of joining
Create a variable of that structure, input some value from user and then display those values.

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;
int main ()
{
 printf ("Enter roll no. : ");
 scanf ("%d",&b.roll);

 fflush (stdin);
 printf ("Enter name: ");
 gets (b.name);

 fflush (stdin);
 printf ("Enter department: ");
 gets (b.department);

 fflush (stdin);
 printf ("Enter course: ");
 gets (b.course);

 printf ("Enter year: ");
 scanf ("%d",&b.year);

 printf("\nRoll number: %d\nName: %s\nDepartment: %s\nCourse: %s\nYear: %d\n",b.roll,b.name,b.department,b.course,b.year);

 printf ("\npress any key to close.");
 getch();
}

Sample Output

display user input data using structure

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact