Wednesday, 3 January 2018

Structure array input output program

Q : Define a structure of employees of an organization with the following fields:
Empno, Empname, Date_of_joining, Salary, Department
Write a program which accepts names of ten employees and print them on the screen

Solution : 



/*==============================
     Girfa Student Help
     Program : Structure 10 record input/output
     More Program : http://girfahelp.blogspot.in/p/c-language-structure-programming.html
================================*/
#include<stdio.h>
#include<conio.h>
typedef struct stu
{
     int Empno;
     char Empname[50];
     char Date_of_joining[12];
     int Salary;
     char Department[30];
}Student;

void printline(int);
void main()
{
     Student ar[10];
     int i;
     clrscr();
     for(i=0;i<10;i++)
     {
          printf("\n\nInput for %d'st record\n",i+1);
          printf("Enter Employee No. >> ");
          scanf("%d",&ar[i].Empno);
          printf("Enter name of employee>> ");
          fflush(stdin);
          gets(ar[i].Empname);
          printf("Enter date of join>> ");
          fflush(stdin);
          gets(ar[i].Date_of_joining);
          printf("Enter Salary>> ");
          scanf("%d",&ar[i].Salary);
          printf("Enter Department of employee>> ");
          fflush(stdin);
          gets(ar[i].Department);

     }
     for(i=0;i<10;i++)
     {
          clrscr();
          printline(50);
          printf("\n\t\t%d'st record data\n",i+1);
          printf("\n\tEmployee No.:\t%d",ar[i].Empno);
          printf("\n\tName :\t%s",ar[i].Empname);
          printf("\n\tDate of joining : \t%s",ar[i].Date_of_joining);
          printf("\n\tSalary:\t%d",ar[i].Salary);
          printf("\n\tDepartment : \t%s\n",ar[i].Department);
          printline(50);
          getch();
     }
}
void printline(int n)
{
     int i;
     for(i=1;i<=n;i++)
          printf("*");
}

No comments:

Post a Comment