Create a program that will store the salary of an employee, and add 15% increment to it.
Answers
Answer:
#include<stdio.h>
#include<pthread.h>
struct emp
{
char name[10];
int salary;
int no;
}*t;
int nthread,n;
void *work(void *);
main()
{
pthread_t id;
struct emp e[5];
int i;
printf("Enter The No Of Thread");
scanf("%d",&nthread);
printf("Enter The No of Element");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Employee Name : ");
scanf("%s",&e[i].name);
printf("Enter the Employee Salary : ");
scanf("%d",&e[i].salary);
}
/*for(i=0;i<n;i++)
{
printf("%s",e[i].name);
printf("%d\n",e[i].salary);
}*/
for(i=0;i<nthread;i++)
{
e[0].no=i;
if(0==pthread_create(&id,NULL,work,(void *)&e))
{
continue;
}
else
{
printf("Problem In Thread Creation");
}
}
pthread_join(id,NULL);
printf("\n\nAfter Updation\n");
printf("E_Name\tE_salary\n");
for(i=0;i<n;i++)
{
printf("%s\t",e[i].name);
printf("%d\n",e[i].salary);
}
}
void *work(void *e)
{
int j,i;
t=(struct emp *)e;
// printf("%d",t[0].no); for(j=t[0].no;j<n;j+=nthread)
{
t[j].salary=t[j].salary+(t[j].salary*0.15);
}
pthread_exit(NULL);
}
/* OUTPUT:
---------
Enter The No Of Thread2
Enter The No of Element6
Enter the Employee Name : rohit
Enter the Employee Salary : 5000
Enter the Employee Name : rakesh
Enter the Employee Salary : 6000
Enter the Employee Name : amit
Enter the Employee Salary : 8000
Enter the Employee Name : amir
Enter the Employee Salary : 9000
Enter the Employee Name : govinda
Enter the Employee Salary : 6000
Enter the Employee Name : ram
Enter the Employee Salary : 80000
After Updation
E_Name E_salary
rohit 5749
rakesh 6899
amit 9199
amir 10349
govinda 6899
ram 91999
*/