=========================================================================
B ))) //Program to enter n number of employee details by using a structure called emp
#include<stdio.h>
#include<conio.h>
struct emp
{
char name[20];
char dept[20];
int code;
};
void main()
{
struct emp e[20];
int i,n;
clrscr();
printf("Enter number of employee\n");
scanf("%d\n",&n);
for(i=0;i<=n;i++)
printf("Enter employee name\n");
scanf("%s",e[i].name);
printf("Enter department\n");
scanf("%s",e[i].dept);
printf("Enter employee code\n");
scanf("%d",&e[i].code);
clrscr();
printf("Name\tDepartment\tcode\n");
for(i=0;i<=n;i++)
{
printf("%s\t%s\t%d\n",e[i].name,e[i].dept,e[i].code);
}
getch();
}
-------------------------------------------------------------------------------
Output
Enter number of employee
2
Enter employee name
aaa
Enter department
Computer Science
Enter employee code
11
Enter employee name
bbb
Enter department
Maths
Enter employee code
22
This will print as :
Name Dept code
aaa cs 11
bbb maths 22
===============================================
C ))) //Program to enter n number of student details,
enter 3 subject mark, and find total marks (by using a structure called student)
#include<stdio.h>
#include<conio.h>
struct student
{
int rno;
char name[20];
int m1,m2,m3,t;
};
void main()
{
clrscr();
struct student s[20];
int i,n;
printf("Enter number of students\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter roll no\n");
scanf("%d",&s[i].rno);
printf("Enter name\n");
scanf("%s",s[i].name);
printf("Enter 3 subject marks\n");
scanf("%d%d%d",&s[i].m1,&s[i].m2,&s[i].m3);
s[i].t=s[i].m1+s[i].m2+s[i].m3;
}
clrscr();
printf("Details of the student is..\n");
printf("Name\tRno\tMark1\tMark2\tMark3\tTotal\n");
for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t%d\t%d\t%d\n",s[i].name,s[i].rno,s[i].m1,s[i].m2,s[i].m3,s[i].t);
getch();
}
}
-------------------------------------------------------------
Output
Enter number of students
2
Enter roll no
1
Enter name
aa
Enter 3 subject marks
21
34
56
Enter roll no
2
Enter name
bb
Enter 3 subject marks
65
65
89
Roll no name mark1 mark2 mark3 total
2 bb 65 65 89 219
===============================================
Back to Home & C