Monday 8 February 2016

WAP to define a structure with the following specification

 WAP to define a structure with the following specification
            Structure name            Emp
            Ecode                          integer                                    
            Ename                         character array
            Basic salary                 float
            Hra                              float                             40% of basic salary
            Da                               float                             20% of basic salary
            Ta                                float                             10% of basic salary
            Gross salary                 float                             basic salary + hra + da + ta
            It                                 float                             20 % of gross salary   
            Pf                                float                             10% of gross salary
            Net salary                    float                             gross salary – (it + pf)
           
Now perform the following operations:
            (1) Take an object of the given structure, input the values for the ecode, ename, basic salary, calculate all other values and display the values.

            (2) Take an array of objects of size 10 of the given structure and input, calculate and display the values for 10 employees.


#include<stdio.h>
#include<conio.h>
struct emp
{int ecode;
char ename[1000];
int sal;
int hra;
int da;
int ta;
int gs;
int it;
int pf;
int netsal;
};
void main()
{
struct emp e[10];
int i;
clrscr();
for(i=0;i<=10;i++) for 10 student
{
printf("enter info of emp");
printf("enter name ");
scanf("%s",e[i].ename);
printf("enter emp code");
scanf("%d",&e[i].ecode);
printf("enter sal to find hra,da,ta,gs,it,pf,netsal");
scanf("%d",&e[i].sal);
e[i].hra=(e[i].sal*40)/100;
e[i].da=(e[i].sal*20)/100;
e[i].ta=(e[i].sal*10)/100;
e[i].gs=(e[i].sal+ e[i].hra+e[i].da+e[i].ta);
e[i].it=(e[i].gs*20)/100;
e[i].pf=(e[i].gs*10)/100;
e[i].netsal=(e[i].gs-(e[i].it+e[i].pf));
}
for(i=0;i<=10;i++)
{
printf("\ninfo\n");
printf("name: %s\n",e[i].ename);
printf("code: %d\n",e[i].ecode);
printf("sal: %d\n",e[i].sal);
printf("hra: %d\n",e[i].hra);
printf("da: %d\n",e[i].da);
printf("ta: %d\n",e[i].ta);
printf("gs: %d\n",e[i].gs);
printf("it: %d\n",e[i].it);
printf("pf: %d\n",e[i].pf);
printf("netsal: %d\n",e[i].netsal);
}

No comments:

Post a Comment