0% found this document useful (0 votes)
2 views

Simple Structure Code

The document contains multiple C programs demonstrating the use of structures and unions. It includes examples for reading and displaying student and employee data, filtering employees based on salary, and handling multiple entries with size allocation comparisons between structures and unions. Each program illustrates basic input/output operations and data management using C programming constructs.

Uploaded by

dedarkshadowyt66
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Simple Structure Code

The document contains multiple C programs demonstrating the use of structures and unions. It includes examples for reading and displaying student and employee data, filtering employees based on salary, and handling multiple entries with size allocation comparisons between structures and unions. Each program illustrates basic input/output operations and data management using C programming constructs.

Uploaded by

dedarkshadowyt66
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Simple Structure Code

#include<stdio.h>
struct hello
{
int rn;
char name[20];
char sec[5];
};
int main()
{
struct hello n1;
printf("Enter the roll no. of student: ");
scanf("%d",&n1.rn);

printf("Enter the name of the student: ");


scanf("%s",n1.name);

printf("Enter the section of the student: ");


scanf("%s",n1.sec);
printf("\n");

printf("Roll no.:%d Name:%s Section:%s",n1.rn,n1.name,n1.sec);


return 0;
}
WAP to read multiple employee(emp_id,
emp_name, emp_salary) & display the
structure.
#include<stdio.h>
struct Employee
{
int emp_id;
char emp_name[20];
float emp_salary;
};
int main()
{
int i;
struct Employee data[3];
{
for(i=0;i<3;i++)
{

printf("Enter the ID of the employee: ");


scanf("%d",&data[i].emp_id);

printf("Enter the name of the employee: ");


scanf("%s",data[i].emp_name);

printf("Enter the salary of the employee: ");


scanf("%f",&data[i].emp_salary);

printf("\n");
}
for(i=0;i<3;i++)
{
printf("ID:%d Name:%s Salary:%f \
n",data[i].emp_id,data[i].emp_name,data[i].emp_salary);
}
}
return 0;
}
WAP to read multiple employee(emp_id,
emp_name, emp_salary) & display whose
salary is greater than 10,000.
#include<stdio.h>
struct Employee
{
int emp_id;
char emp_name[20];
float emp_salary;
};
int main()
{
int i;
struct Employee data[5];
{
for(i=0;i<5;i++)
{

printf("Enter the ID of the employee: ");


scanf("%d",&data[i].emp_id);

printf("Enter the name of the employee: ");


scanf("%s",data[i].emp_name);

printf("Enter the salary of the employee: ");


scanf("%f",&data[i].emp_salary);

printf("\n");
}
for(i=0;i<5;i++)
{
if(data[i].emp_salary>10000)
printf("ID:%d Name:%s Salary:%f \
n",data[i].emp_id,data[i].emp_name,data[i].emp_salary);
}
}
return 0;
}
WAP to read multiple structure data & display
whose salary is between any two numbers.
#include<stdio.h>

struct idktable
{
int id;
char name[20];
float salary;
};

int main()
{

struct idktable idk[99999];


int i,n,x;

printf("Enter the no of employee: ");


scanf("%d",&n);

printf("\n");

if(n<99999)
{
for(i=0;i<n;i++)
{

printf("Enter the ID of the employee: ");


scanf("%d",&idk[i].id);
printf("Enter the name of the employee: ");
scanf("%s",idk[i].name);

printf("Enter the salary of the employee: ");


scanf("%f",&idk[i].salary);

printf("\n");
}

for(i=0;i<n;i++)
{
printf("ID:%d Name:%s Salary:%f \n",idk[i].id,idk[i].name,idk[i].salary);
}
}

else
{
x=99999-n;

printf("I can't hanlde this much employee.\n");


printf("Fire atleast %d of your employee to access the structure.\n",x);
}

return 0;
}
Size allocation in Union structure & simple
structure with same variables.
#include<stdio.h>
#include<string.h>
struct table
{
int id;
char name;
float no;
};
union table2
{
int id;
int name;
float no;
};
int main()
{
struct table a;
union table2 b;
printf("The total size of the structure: %d \n",sizeof(a));
printf("The total size of the union structure: %d",sizeof(b));
}

You might also like