Monday, 30 January 2017

C Language Structure Record Entry

NIELIT O Level Solved Paper
January 2016
C Language

Q8 b) Write a program to create a structure Employee having empCode, name, department, address and salary as its members. Read the details for 10 employees and then display them.

Solution : 

#include<stdio.h>
#include<conio.h>
struct stu
{
     int empcode;
     char name[20];
     char dept[20];
     char address[20];
     int sal;

};

void main()
{
     struct stu ob[3];
     int i;
     clrscr();
     for(i=0;i<3;i++)
     {
           printf("\n%d 'st record input\n",i+1);
           printf("Enter emp code");
           scanf("%d",&ob[i].empcode);
           printf("Enter Name>> ");
           scanf("\n%s",&ob[i].name);
           printf("Enter Department>> ");
           scanf("\n%s",&ob[i].dept);
           printf("Enter Addess>> ");
           scanf("\n%s",&ob[i].address);
           printf("Enter Salary>> ");
           scanf("%d",&ob[i].sal);
     }
     for(i=0;i<3;i++)
     {
           printf("\n%d Record\n",i+1);
           printf("\nEmpcode\t%d",ob[i].empcode);
           printf("\nName\t%s",ob[i].name);
           printf("\nDepartment\t%s",ob[i].dept);
           printf("\nAddress\t%s",ob[i].address);
           printf("\nSal\t%d",ob[i].sal);
     }
     getch();

}