Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Structures and Pointers

#include <stdio.h>
#include <conio.h>
int main()
{
{`//char name_of_company[50];`}
int no_of_employees;
typedef struct{
int employee_id;
char name[50];
char sex;
int salary;
} employee;
employee emp[50];
printf("Create employee database for a company.\n");
printf("Enter the name of company: ");
scanf("%s",name_of_company);
printf("\nEnter no. of employees(Max. limit of 50): ");
scanf("%d",&no_of_employees);
int i=0;
int total=0;
for (i=0;i<no_of_employees;i++)
{
printf("\nEnter employee id: ");
scanf("%d",&emp[i].employee_id);
printf("\nEnter employee name with '-' between names: ");
scanf("%s",emp[i].name);
printf("\nEnter sex of employee(m/f): ");
emp[i].sex = getche();
printf("\nEnter salary of employee: ");
scanf("%d",&emp[i].salary);
total = total + emp[i].salary;
}
printf("\nPrinting database ... ");
printf("\n\t\t%s",name_of_company);
printf("\nNumber of Employees: %d",no_of_employees);
printf("\nTotal Salary of employees: %d",total);
printf("\n----------------------------------");
printf("\nID\tName\t\tSex\tSalary");
for(i=0;i<no_of_employees;i++)
{
printf("\n%d\t%s\t\t%c\t%d",emp[i].employee_id,emp[i].name,emp[i].sex,emp[i].salary);
}
getch();
return;
}

The output is shown below:
Structure Pointer Out Put

Topics in C Programming

Structures And Pointers Homework Help
Copyright © 2009-2023 UrgentHomework.com, All right reserved.