We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
PPS
PRACTICAL 8
PROGRAM WITH SOLUTION
Program 1: Define a structure type struct personal that would contain person name, date
of joining and salary using this structure to read this information of 5 people and print the
same on screen.
Solution:
#include
Hinclude
struct personal
{
char name|20};
char date[20];
float salary;
i
void main()
{
struct personal person{5];
int i
clrscr();
for 1=0;1<5;i#4)
{
printf("enter details of person %d : \n", i#1);
printf("enter name :");
scanf("%s", personfiJ.name);
gets(person|i].name);
printf("enter joining date (dd-mm-year) :");
scanf("%s", personfi.date);
gets(person{iJ.date);
fflush(stdin};
printf("enter salary
scanf("s6f", &person[i].salary);
}
pic 5; #4)
printf("\ndetails of %d person : \n", i#1);
printf("name = %s\n",personfi].name);
printf("joining date = %s\n",person|i].date);
printf("salary = %f\n",person{i}.salary);
}
getch();Program 2: Define structure data type called time_struct containing three member's integer
hour, integer minute and integer second. Develop a program that would assign values to
the individual number and display the time in the following format: 16: 40:51
Solution:
#linclude
#include
struct time
{
int hours;
int minutes;
int seconds;
i
void main( )
{
struct time t1,t2; _//time structure variable
int h, m, 5;
clrser();,
printf("enter time 1: \n
printf("enter hours: ");
scanf("g6d", &t1.hours);
printf("enter minutes: ");
scanf("s%d", &t1.minutes);
printf("enter seconds: ");
scanf("s%6d", &t1.seconds);
printf ("The Time 1 is %d : %d : %d'", t1 hours, t1.minutes, t1.seconds);
printf("\nenter time 2: \n");
printf("enter hours: ");
scanf("s6d", &t2.hours);
printf("enter minutes: ");
scanf("géd", &t2.minutes);printf("enter seconds: ");
scanf("g%éd", &t2.seconds);
printf ("The Time 2 is 96d : 9d : 9d", t2.hours, t2.minutes, t2.seconds);
h= t1.hours + t2.hours;
m = t1minutes + t2.minutes;
= t.seconds + t2.seconds;
printf ("\nSum of the two time's is %d:%d:%d", h, m, s);
getch();
Te
a
ee teen
en eee)
ey ae
earinee
cea
reared
Oe
Program 3: Define a structure called cricket that will describe the following information:
Player name, Team name, Batting average. Using cricket, declare an array player with 50
elements and write a C program to read the information about all the 50 players and print
team wise list containing names of players with their batting average.
Solution:
Hinclude
Hinclude
struct players
{
char player_name[25], team_name[25};
float batting_avg;
} ply[S0};,
int main()
{
int i,j;
struct players temp;
printf("enter number of players");
scanf("%d", &n);for(i=O;i 0)
{
‘temp = ply[j-1];
plyli-4] = plytil;
ply[j] = temp;
}
}
}
printf("\nDetails of players");
for 1=0;i
#include
struct student
{
char name[50];
char branch{50];
int total;
i
void main( )
{
inti;
struct student s1{10];
clrser();
for( i= 0;1<3 ;i+#)
{
printf("Enter Student Name :");
scanf("%s", s1[i].name);
printf("Enter Student Branch : ");
scanf("%s", s1[i].branch);
printf("Enter Student Total Marks : ");
scanf("%d", &s1[i].total);printf("Display Student Details\n");
for(i=0;i<3 ;i++)
{
printf("Student Name: %s\n", s1[i].name);
printf("Student Branch: %s\n", s1[i].branch);
printf("Student Total Marks: %d\n", s1[i].total);
}
getch();
‘J
Py
it
Fr)
Name : mahendra
cir eras ots ees
Riera rete eet)
ers
Rr
Sire
en
Total Marks: 150
Pees
cee
Peeve eee)
permet
Branch: me
eee eer
Program 5: Write a program in C using structure to enter rolino, marks of the three subject
for 3 students and find total obtained by each student.
Solution:
#include
#include
struct marks
{
int rolino;
int sub1;
int sub:
int sub3;
int total;
i
void main()
{
struct marks student{3];
inti;clrser();
for( i= 0; <3 ;i++)
{
}
printf("enter student %d roll no :", i+);
scanf("g%d", &student{i.rollno);
printf("enter student %d subject 1 marks :", i#1);
scanf("%d", &student[i).sub1);
printf("enter student %d subject 2 marks :", i#1);
scanf("%d", &student[i).sub2);
printf("enter student %éd subject 3 marks :", i#1);
scanf("%d", &student[i).sub3);
for(i=0;1<3; i++)
{
}
student{[i].total = studentti].sub1 + studentti].sub2 + studentt[i].sub3;
printf("STUDENT \t TOTAL\n");
for(i=0;i<3 ;i++)
{
}
printi("'Student{%d] \t 9d\n", i#1, student{i].total);
getch();
Er
errs
i
roll no :
ert
nee
a)
subject
Pa a
era
ered
ered
Bn
150
re)
Ec)