Tuesday, September 9, 2014

write a program display user input data using 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 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 stud
{
 char name[30];
 int roll_no;
 char department[30];
 char course[30];
 int year;
}
int main()
{
 struct stud s1;

 printf ("Enter name, ID, department, course, year : ");
 scanf("%s%d%s%s%d",&s1.name,&s1.roll_no,&s1.department,&s1.course,&s1.year);

 printf("And here is whhat you have entered\n");
 printf("Name = %s\n\nRoll No. = %d\n\nDepartment = %s\n\nCopurse = %s\n\nYear = %d\n\n",s1.name,s1.roll_no,s1.department,s1.course,s1.year);

 system("pause");
 return 0;
}

Sample Output


display user roll# name using struct

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