Tuesday, September 9, 2014

Display user input data by using an array of structure, add user roll number, name, department, course, and year of joining


Problem

Create a structure to specify data on students given below:
  • Roll number
  • Name
  • Department
  • Course
  • Year of joining
Create above program by declaring an array of 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 stud
{
 char name[30];
 int roll_no;
 char department[30];
 char course[30];
 int year;
}
int main()
{
 struct stud s[5];
 int i;

 for (i=0;i<5;i++)
 {
  printf ("Enter name, ID, department, course, year : ");
  scanf("%s%d%s%s%d",&s[i].name,&s[i].roll_no,&s[i].department,&s[i].course,&s[i].year);
}

 for (i=0;i<5;i++)
 {
  printf("And here is whhat you have entered\n\n");
  printf("Name = %s\n\nRoll No. = %d\n\nDepartment = %s\n\nCopurse = %s\n\nYear = %d\n\n",s[i].name,s[i].roll_no,s[i].department,s[i].course,s[i].year);
 }

 system("pause");
 return 0;
}

Sample Output

display user roll# name using array of 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