Experiment No.9
Experiment No.9
9
Objective: Write a C program to create Employee record for 2
Employees by using runtime(Variables are name, id , salary)
Code:
#include<stdio.h>
#include<string.h>
struct Employee
char name[50];
int id;
float salary;
};
void main()
int i;
for(i=0;i<2;i++)
scanf("%s",&emp[i].name);
scanf("%d",&emp[i].id);
printf("Enter the salary of %d Employye :",i+1);
scanf("%f",&emp[i].salary);
for(i=0;i<2;i++)
printf("Name : %s\n",emp[i].name);
printf("ID : %d\n",emp[i].id);
printf("salary : %f\n",emp[i].salary);
Output Window:
2) Write A C program to create a student record for only one
student by using array within a structure(Consider runtime , the
variable are(name, roll no, marks for five subjects)
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
char name[50];
int rollno;
int marks[5];
};
void main()
struct student S;
int i;
clrscr();
scanf("%s %d",&S.name,&S.rollno);
printf("Enter marks for 5 subject:\n");
for(i=0;i<=4;i++)
scanf("%d",&S.marks[i]);
} printf("Name:%s\n",S.name);
printf("Rollno:%d\n",S.rollno);
for(i=0;i<=4;i++)
printf("\nSubject %d %d\n",i+1,S.marks[i]);
Output window: