SlideShare a Scribd company logo
1 of 29
Download to read offline
33
Set 3 Q1 Define a structure called cricket that will describe the following
information.
Player name, Team name, Batting Average
Using cricket declare an array player with n elements and write a program to read
the information about all the n elements and print a team-wise listing containing
names of players with their batting average
Program
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct cricket
{
char plyname[20];
char teamname[20];
float batavg;
};
int main()
{
struct cricket *player;
int i, no,j,k,nop;
char team[20][20], temp[20][20], temp1[20];
printf("Enter number of players ");
scanf("%d", &no);
nop=no;
player = (struct cricket*) malloc (no * sizeof(struct cricket));
34
for(i = 0; i < no; i++)
{
printf("Details of Player %dn",i+1);
fflush(stdin);
printf("Enter the Player Name : ");
gets((player+i)->plyname);
fflush(stdin);
printf("Enter the Team Name : ");
gets((player+i)->teamname);
fflush(stdin);
printf("Enter the Batting Average : ");
scanf("%f",&((player+i))->batavg);
}
for(i = 0; i < no; i++)
{
strcpy(team[i],(player+i)->teamname);
strcpy(temp[i],team[i]);
}
for (i = 0; i < no; i++)
{
for (j = i + 1; j < no;)
{
if (strcmp(temp[j],team[i])==0)
{
for (k = j; k < no; k++)
{
35
strcpy(temp[k], temp[k + 1]);
}
no--;
}
else
j++;
}
}
printf("n Player's Details:n");
printf("Country tt Name tt Batting Averagen");
for(i=0;i<j;i++)
{
printf("%sn",temp[i]);
strcpy(temp1,temp[i]);
for(k=0;k<nop;k++)
{
if(strcmp((player+k)->teamname,temp1)==0)
printf("ttt%sttt%.2fn",(player+k)->plyname,
(player+k)->batavg);
}
}
free (player);
return 0;
}
36
Output
Enter the Player Name : dhoni
Enter the Team Name : australia
Enter the Batting Average : 89
Details of Player 3
Enter the Player Name : ricky
Enter the Team Name : australia
Enter the Batting Average : 56
Details of Player 4
Enter the Player Name : ganguly
Enter the Team Name : india
Enter the Batting Average : 62
Details of Player 5
Enter the Player Name : sreesanth
Enter the Team Name : kenya
Enter the Batting Average : 82
Player's Details:
Country Name Batting Average
india
sachin 78.00
ganguly 62.00
australia
dhoni 89.00
ricky 56.00
kenya
sreesanth 82.00
37
Set 3 Q2 Define a structure that can describe a Hotel. It should have members
that include the name, address, grade, average room charge and number of rooms.
Write functions to perform the following operations:
a)To print out hotels of a given grade in order of charges.
b)To print out hotels with room charges less than a given value.
Program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct details
{
char name[40],address[40],grade;
float rate;
int num;
};
void search1(struct details *ob,char g,int n);
void search2(struct details *ob,float r,int n);
int main()
{
struct details *hotel;
int n,i;
char g;
38
float rate;
puts("Enter the number of hotels:");
scanf("%d",&n);
hotel = (struct details*) malloc (n * sizeof(struct details));
for(i=0;i<n;i++)
{
printf("Details of hotel %dn",i+1);
fflush(stdin);
printf("Enter the hotel name:");
gets((hotel+i)->name);
fflush(stdin);
printf("Enter the hotel address:");
gets((hotel+i)->address);
fflush(stdin);
printf("Enter the hotel grade:-('a','b','c','d')");
scanf("%c",&(hotel+i)->grade);
fflush(stdin);
puts("Enter the room charge:");
scanf("%f",&(hotel+i)->rate);
fflush(stdin);
puts("Enter the room numbers:");
scanf("%d",&(hotel+i)->num);
}
fflush(stdin);
39
printf("Search for specific hotelsn");
printf("Enter the grade for hotel('a','b','c','d'):");
scanf("%c",&g);
search1(hotel,g,n);
printf("nEnter the maximum charge:");
scanf("%f",&rate);
search2(hotel,rate,n);
return 0;
}
void search1(struct details *ob,char g,int n)
{
int i,j,x=0;
int flag=1;
char final[n][40],temp[40];
float r[n],t;
for(i=0;i<n;i++)
{
if(g==ob[i].grade)
{
strcpy(final[x],ob[i].name);
r[x]=ob[i].rate;
x++;
flag=0;
}
}
for(i=0;i<x;i++)
40
{
for(j=i+1;j<x;j++)
{
if(r[i]>r[j])
{
t=r[i];
r[i]=r[j];
r[j]=t;
strcpy(temp,final[i]);
strcpy(final[i],final[j]);
strcpy(final[j],temp);
}
}
}
if (flag==0)
{
printf("Hotel names with specified GRADE in order of charge");
for(i=0;i<x;i++)
{
printf("n%stt%.2f",final[i],r[i]);
}
}
else
printf("Hotel in the grade %c not available", g);
}
void search2(struct details *ob,float r1,int n)
41
{
int i,x=0;
int flag=1;
char final[n][40];
float r[n];
for(i=0;i<n;i++)
{
if(r1>ob[i].rate)
{
r[x]=ob[i].rate;
strcpy(final[x],ob[i].name);
x++;
flag=0;
}
}
if (flag==0)
{
printf("Hotel names below the specified RATE.");
for(i=0;i<x;i++)
{
printf("n%stt%.2f",final[i],r[i]);
}
}
else
printf("No hotel room below %0.2f available", r1);
}
42
Output
Enter the number of hotels:
5
Details of hotel 1
Enter the hotel name:rudra
Enter the hotel address:calicut
Enter the hotel grade:-('a','b','c','d')a
Enter the room charge:
250
Enter the room numbers:
10
Details of hotel 2
Enter the hotel name:agni
Enter the hotel address:kochi
Enter the hotel grade:-('a','b','c','d')a
Enter the room charge:
500
Enter the room numbers:
20
Details of hotel 3
Enter the hotel name:prithvi
Enter the hotel address:pathanamthitta
Enter the hotel grade:-('a','b','c','d')b
Enter the room charge:
1000
Enter the room numbers:
43
5
Details of hotel 4
Enter the hotel name:solo
Enter the hotel address:trivandrum
Enter the hotel grade:-('a','b','c','d')c
Enter the room charge:
100
Enter the room numbers:
30
Details of hotel 5
Enter the hotel name:sagar
Enter the hotel address:trivandrum
Enter the hotel grade:-('a','b','c','d')a
Enter the room charge:
500
Enter the room numbers:
5
Search for specific hotels
Enter the grade for hotel('a','b','c','d'):a
Hotel names with specified GRADE in order of charge
rudra 250.00
agni 500.00
sagar 500.00
Enter the maximum charge:300
Hotel names below the specified RATE.
rudra 250.00
solo 100.00
44
Set 3 Q3 Define a structure named mea_class which include the following
members:
Roll number, Name, mark of 5 subjects.
Write a program to calculate the aggregate percentage and the grade of each
student, and print the details in a neat format. The constraint for grading is as
follows:
Aggregate % Grade
>=95 A++
>=85 and <95 A+
>=80 and <85 A
>=75 and <80 B++
>=70 and <75 B+
>=60 and <70 B
>=50 and <60 C
<50 F
Program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct mca_class
{
int rollno;
char name[40];
int mark[5];
float per;
45
char grade[3];
};
void read (struct mca_class *student,int n);
void display(struct mca_class *student,int n);
int main()
{
struct mca_class *student;
int n;
puts("Enter the number of students");
scanf("%d",&n);
student = (struct mca_class*) malloc (n * sizeof(struct mca_class));
read (student,n);
display (student,n);
return 0 ;
}
void read (struct mca_class *student,int n)
{
int i,j;
float total,per;
char gr[3];
for(i=0;i<n;i++)
{
46
fflush(stdin);
printf("Student Roll No:");
scanf("%d",&(student+i)->rollno);
fflush(stdin);
printf("Enter the Student name:");
gets((student+i)->name);
fflush(stdin);
printf("Enter the mark of subjects out of 100 n");
total=0;
for (j=0;j<5;j++)
{
printf("Enter the mark of subject %d:",j+1);
scanf("%d",&(student+i)->mark[j]);
total=total+(student+i)->mark[j];
}
per=total/5;
student[i].per=per;
printf("%0.2f,",per);
if (per>=95)
strcpy(gr,"A++");
else if ((per>=85)&&(per<95))
strcpy(gr,"A+");
else if ((per>=80)&&(per<85))
strcpy(gr,"A");
else if ((per>=75)&&(per<80))
strcpy(gr,"B++");
else if ((per>=70)&&(per<75))
47
strcpy(gr,"B+");
else if ((per>=60)&&(per<70))
strcpy(gr,"B");
else if ((per>=50)&&(per<60))
strcpy(gr,"C");
else
strcpy(gr,"F");
strcpy((student+i)->grade,gr);
}
}
void display(struct mca_class *student,int n)
{
int i,j;
if(student == NULL)
{
printf("ERROR !!! NULL pointer !!!n");
return;
}
else
{
printf("List of students:n");
printf("=========================n");
printf("Roll NotNametMark 1tMark 2tMark 3tMark 4tMark
5tPertGraden");
48
printf("===============================================
==========================n");
for(i=0;i<n;i++)
{
printf("%dt%s",(student+i)->rollno,(student+i)-
>name);
for(j=0;j<5;j++)
{
printf("t%d",(student+i)->mark[j]);
}
printf("t%.2ft%sn",(student+i)->per,(student+i)-
>grade);
}
printf("n");
}
}
Output
Enter the number of students
5
Student Roll No:1
Enter the Student name:aakash
Enter the mark of subjects out of 100
Enter the mark of subject 1:80
Enter the mark of subject 2:45
Enter the mark of subject 3:35
Enter the mark of subject 4:14
49
Enter the mark of subject 5:78
Student Roll No:2
Enter the Student name:binu
Enter the mark of subjects out of 100
Enter the mark of subject 1:48
Enter the mark of subject 2:23
Enter the mark of subject 3:17
Enter the mark of subject 4:14
Enter the mark of subject 5:85
Student Roll No:3
Enter the Student name:eva
Enter the mark of subjects out of 100
Enter the mark of subject 1:12
Enter the mark of subject 2:10
Enter the mark of subject 3:09
Enter the mark of subject 4:7
Enter the mark of subject 5:05
Student Roll No:4
Enter the Student name:joshi
Enter the mark of subjects out of 100
Enter the mark of subject 1:45
Enter the mark of subject 2:99
Enter the mark of subject 3:98
Enter the mark of subject 4:96
Enter the mark of subject 5:93
Student Roll No:5
Enter the Student name:santhi
50
Enter the mark of subjects out of 100
Enter the mark of subject 1:78
Enter the mark of subject 2:99
Enter the mark of subject 3:91
Enter the mark of subject 4:85
Enter the mark of subject 5:23
List of students:
=========================
Roll No Name Mark 1 Mark 2 Mark 3 Mark 4 Mark 5 Per Grade
=========================================================
1 aakash 80 45 35 14 78 50.40 C
2 binu 48 23 17 14 85 37.40 F
3 eva 12 10 9 7 5 8.60 F
4 joshi 45 99 98 96 93 86.20 A+
5 santhi 78 99 91 85 23 75.20 B++
51
Set 3Q5 Define a structure named employee consisting of the following members:
Employee ID, Name, Department, Basic Salary, DA (in %), HRA(in%).
Write a program to prepare the pay-slip of the employees of a particular
department, using array of structures.
Program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct employee
{
int empid;
char name[40];
char dept[40];
float basic;
float da;
float hra;
float gross;
};
void read (struct employee *emp,int n);
void display(struct employee *emp,char* dept,int n);
int main()
{
52
struct employee *emp;
int n;
char dept[40];
puts("Enter the number of employees");
scanf("%d",&n);
emp = (struct employee*) malloc (n * sizeof(struct employee));
read (emp,n);
puts("Enter the dept name of employees whose pay slip is to be displayed:
n");
fflush(stdin);
gets(dept);;
display (emp,dept,n);
free(emp);
return 0 ;
}
void read (struct employee *emp,int n)
{
int i;
float da,hra;
printf("Enter da rate: ");
scanf("%f",&da);
53
printf("Enter hra rate: ");
scanf("%f",&hra);
for(i=0;i<n;i++)
{
printf("Enter employee ID: ");
scanf("%d",&(emp+i)->empid);
printf("Enter name of the employee: ");
fflush(stdin);
gets((emp+i)->name);
printf("Enter Department name: ");
fflush(stdin);
gets((emp+i)->dept);
printf("Enter Basic salary: n");
scanf("%f",&(emp+i)->basic);
(emp+i)->da = ((emp+i)->basic*da)/100;
(emp+i)->hra = ((emp+i)->basic*hra)/100;
(emp+i)->gross = (emp+i)->basic + (emp+i)->da + (emp+i)->hra;
}
}
void display(struct employee *emp,char* dept,int n)
{
int i,found =0;
54
if(emp == NULL)
{
printf("ERROR !!! NULL pointer !!!n");
return;
}
else
{
printf("nPay-slip of employees of department : %sn",dept);
printf("n");
printf("Emp IDtNametBasictDAtHRAtGross Salaryn");
printf("===============================================
===========n");
for(i=0;i<n;i++)
{
if(strcmp((emp+i)->dept,dept)==0)
{
printf("%dt%st%.2ft%.2ft%.2ft%.2fn",(emp+i)-
>empid,(emp+i)->name,(emp+i)->basic,(emp+i)->da,(emp+i)->hra,(emp+i)-
>gross);
found =1;
}
}
if(found ==0)
printf("nPay-slips NOT FOUND for the requested Dept-
%s!!!!!!!!n",dept);
printf("n");
}
55
}
Output
Enter the number of employees
5
Enter da rate: 5
Enter hra rate: 10
Enter employee ID: 1
Enter name of the employee: sarun
Enter Department name: it
Enter Basic salary:
1000
Enter employee ID: 2
Enter name of the employee: sajan
Enter Department name: sales
Enter Basic salary:
2000
Enter employee ID: 3
Enter name of the employee: joby
Enter Department name: it
Enter Basic salary:
5000
Enter employee ID: 4
Enter name of the employee: ginu
Enter Department name: it
Enter Basic salary:
2000
56
Enter employee ID: 5
Enter name of the employee: shibu
Enter Department name: marketing
Enter Basic salary:
5400
Enter the dept name of employees whose pay slip is to be displayed:
it
Pay-slip of employees of department : it
Emp ID Name Basic DA HRA Gross Salary
=========================================================
1 sarun 1000.00 50.00 100.00 1150.00
3 joby 5000.00 250.00 500.00 5750.00
4 ginu 2000.00 100.00 200.00 2300.00
57
Set 3 Q5Write a program to accept records of the different states using array of
structures. The structure should contain state_name, population, literacy_rate and
per_capita_income. Assume suitable data. Display the state whose literacy rate is
highest and whose per capita income is highest. (use typedef in the program).
Program
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct statedemography
{
char state_name[50];
long int population;
float literacy_rate;
float per_capita_income;
}statedetails;
void readstate(statedetails * , int );
void printstate(statedetails * , int);
int main(void)
{
int n;
statedetails *state;
58
printf("Enter the number of states: ");
scanf("%d", &n);
state = (statedetails*)malloc(sizeof(statedetails)*n);
readstate(state, n);
printstate(state, n);
free(state);
return 0;
}
void readstate(statedetails *state, int n)
{
int i;
for(i=0;i<n;i++)
{
printf("Enter name of the state: n");
fflush(stdin);
gets((state+i)->state_name);
printf("nEnter population: n");
scanf("%ld",&(state+i)->population);
printf("Enter literacy rate: n");
scanf("%f",&(state+i)->literacy_rate);
printf("Enter per capita income: n");
59
scanf("%f",&(state+i)->per_capita_income);
}
}
void printstate(statedetails *state, int n)
{
int i;
if(state == NULL)
{
printf("ERROR !!! NULL pointer !!!n");
return;
}
else
{
float maxLiteracy, maxpercapIncome;
i=0;
maxLiteracy = (state+i)->literacy_rate;
maxpercapIncome = (state+i)->per_capita_income;
for(i=1;i<n;i++)
{
if ((state+i)->literacy_rate > maxLiteracy)
maxLiteracy = (state+i)->literacy_rate;
if ((state+i)->per_capita_income > maxpercapIncome)
60
maxpercapIncome = (state+i)->per_capita_income;
}
for(i=0;i<n;i++)
{
if ((state+i)->literacy_rate == maxLiteracy)
printf("State %s",(state+i)->state_name);
printf(" have Maximum literacy
rate:%.2fn",maxLiteracy);
}
printf("n");
for(i=0;i<n;i++)
{
if ((state+i)->per_capita_income == maxpercapIncome)
printf("State %s ",(state+i)->state_name);
printf(" have Maximum per capita
income:%.2fn",maxpercapIncome);
}
printf("n");
}
}
61
Output
Enter the number of states: 5
Enter name of the state: kerala
Enter population: 15000
Enter literacy rate: 99
Enter per capita income: 5000
Enter name of the state: bihar
Enter population: 58000
Enter literacy rate: 85
Enter per capita income: 1500
Enter name of the state: gujarat
Enter population: 90000
Enter literacy rate: 45
Enter per capita income: 7400
Enter name of the state: punjab
Enter population: 56000
Enter literacy rate: 23
Enter per capita income: 4800
Enter name of the state: goa
Enter population: 96000
Enter literacy rate: 93
Enter per capita income: 5200
State kerala have Maximum literacy rate:99.00
State gujarat have Maximum per capita income:7400.00

More Related Content

What's hot

What's hot (20)

Types of function call
Types of function callTypes of function call
Types of function call
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
user defined function
user defined functionuser defined function
user defined function
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
C Programming : Pointers and Strings
C Programming : Pointers and StringsC Programming : Pointers and Strings
C Programming : Pointers and Strings
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Array and string
Array and stringArray and string
Array and string
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
Function in c
Function in cFunction in c
Function in c
 
Type conversion
Type  conversionType  conversion
Type conversion
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 

Similar to C programs Set 3

Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...AntareepMajumder
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical fileMitul Patel
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdfmhande899
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1Mook Prapasson
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab PracticeMahmud Hasan Tanvir
 
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxShad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxSonu62614
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdfMOJO89
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfkeerthu0442
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 

Similar to C programs Set 3 (20)

Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
C language
C languageC language
C language
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
pointers 1
pointers 1pointers 1
pointers 1
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxShad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdf
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 

More from Koshy Geoji

Computer Graphics Report
Computer Graphics ReportComputer Graphics Report
Computer Graphics ReportKoshy Geoji
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4Koshy Geoji
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
Vehicle detection in Aerial Images
Vehicle detection in Aerial ImagesVehicle detection in Aerial Images
Vehicle detection in Aerial ImagesKoshy Geoji
 
Hypothesis test based approach for change detection
Hypothesis test based approach for change detectionHypothesis test based approach for change detection
Hypothesis test based approach for change detectionKoshy Geoji
 
73347633 milma-os
73347633 milma-os73347633 milma-os
73347633 milma-osKoshy Geoji
 

More from Koshy Geoji (9)

Computer Graphics Report
Computer Graphics ReportComputer Graphics Report
Computer Graphics Report
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
C programs
C programsC programs
C programs
 
Vehicle detection in Aerial Images
Vehicle detection in Aerial ImagesVehicle detection in Aerial Images
Vehicle detection in Aerial Images
 
Text mining
Text miningText mining
Text mining
 
Hypothesis test based approach for change detection
Hypothesis test based approach for change detectionHypothesis test based approach for change detection
Hypothesis test based approach for change detection
 
Seminar report
Seminar reportSeminar report
Seminar report
 
73347633 milma-os
73347633 milma-os73347633 milma-os
73347633 milma-os
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

C programs Set 3

  • 1. 33 Set 3 Q1 Define a structure called cricket that will describe the following information. Player name, Team name, Batting Average Using cricket declare an array player with n elements and write a program to read the information about all the n elements and print a team-wise listing containing names of players with their batting average Program #include <string.h> #include <stdio.h> #include <stdlib.h> struct cricket { char plyname[20]; char teamname[20]; float batavg; }; int main() { struct cricket *player; int i, no,j,k,nop; char team[20][20], temp[20][20], temp1[20]; printf("Enter number of players "); scanf("%d", &no); nop=no; player = (struct cricket*) malloc (no * sizeof(struct cricket));
  • 2. 34 for(i = 0; i < no; i++) { printf("Details of Player %dn",i+1); fflush(stdin); printf("Enter the Player Name : "); gets((player+i)->plyname); fflush(stdin); printf("Enter the Team Name : "); gets((player+i)->teamname); fflush(stdin); printf("Enter the Batting Average : "); scanf("%f",&((player+i))->batavg); } for(i = 0; i < no; i++) { strcpy(team[i],(player+i)->teamname); strcpy(temp[i],team[i]); } for (i = 0; i < no; i++) { for (j = i + 1; j < no;) { if (strcmp(temp[j],team[i])==0) { for (k = j; k < no; k++) {
  • 3. 35 strcpy(temp[k], temp[k + 1]); } no--; } else j++; } } printf("n Player's Details:n"); printf("Country tt Name tt Batting Averagen"); for(i=0;i<j;i++) { printf("%sn",temp[i]); strcpy(temp1,temp[i]); for(k=0;k<nop;k++) { if(strcmp((player+k)->teamname,temp1)==0) printf("ttt%sttt%.2fn",(player+k)->plyname, (player+k)->batavg); } } free (player); return 0; }
  • 4. 36 Output Enter the Player Name : dhoni Enter the Team Name : australia Enter the Batting Average : 89 Details of Player 3 Enter the Player Name : ricky Enter the Team Name : australia Enter the Batting Average : 56 Details of Player 4 Enter the Player Name : ganguly Enter the Team Name : india Enter the Batting Average : 62 Details of Player 5 Enter the Player Name : sreesanth Enter the Team Name : kenya Enter the Batting Average : 82 Player's Details: Country Name Batting Average india sachin 78.00 ganguly 62.00 australia dhoni 89.00 ricky 56.00 kenya sreesanth 82.00
  • 5. 37 Set 3 Q2 Define a structure that can describe a Hotel. It should have members that include the name, address, grade, average room charge and number of rooms. Write functions to perform the following operations: a)To print out hotels of a given grade in order of charges. b)To print out hotels with room charges less than a given value. Program #include <stdlib.h> #include <stdio.h> #include <string.h> struct details { char name[40],address[40],grade; float rate; int num; }; void search1(struct details *ob,char g,int n); void search2(struct details *ob,float r,int n); int main() { struct details *hotel; int n,i; char g;
  • 6. 38 float rate; puts("Enter the number of hotels:"); scanf("%d",&n); hotel = (struct details*) malloc (n * sizeof(struct details)); for(i=0;i<n;i++) { printf("Details of hotel %dn",i+1); fflush(stdin); printf("Enter the hotel name:"); gets((hotel+i)->name); fflush(stdin); printf("Enter the hotel address:"); gets((hotel+i)->address); fflush(stdin); printf("Enter the hotel grade:-('a','b','c','d')"); scanf("%c",&(hotel+i)->grade); fflush(stdin); puts("Enter the room charge:"); scanf("%f",&(hotel+i)->rate); fflush(stdin); puts("Enter the room numbers:"); scanf("%d",&(hotel+i)->num); } fflush(stdin);
  • 7. 39 printf("Search for specific hotelsn"); printf("Enter the grade for hotel('a','b','c','d'):"); scanf("%c",&g); search1(hotel,g,n); printf("nEnter the maximum charge:"); scanf("%f",&rate); search2(hotel,rate,n); return 0; } void search1(struct details *ob,char g,int n) { int i,j,x=0; int flag=1; char final[n][40],temp[40]; float r[n],t; for(i=0;i<n;i++) { if(g==ob[i].grade) { strcpy(final[x],ob[i].name); r[x]=ob[i].rate; x++; flag=0; } } for(i=0;i<x;i++)
  • 8. 40 { for(j=i+1;j<x;j++) { if(r[i]>r[j]) { t=r[i]; r[i]=r[j]; r[j]=t; strcpy(temp,final[i]); strcpy(final[i],final[j]); strcpy(final[j],temp); } } } if (flag==0) { printf("Hotel names with specified GRADE in order of charge"); for(i=0;i<x;i++) { printf("n%stt%.2f",final[i],r[i]); } } else printf("Hotel in the grade %c not available", g); } void search2(struct details *ob,float r1,int n)
  • 9. 41 { int i,x=0; int flag=1; char final[n][40]; float r[n]; for(i=0;i<n;i++) { if(r1>ob[i].rate) { r[x]=ob[i].rate; strcpy(final[x],ob[i].name); x++; flag=0; } } if (flag==0) { printf("Hotel names below the specified RATE."); for(i=0;i<x;i++) { printf("n%stt%.2f",final[i],r[i]); } } else printf("No hotel room below %0.2f available", r1); }
  • 10. 42 Output Enter the number of hotels: 5 Details of hotel 1 Enter the hotel name:rudra Enter the hotel address:calicut Enter the hotel grade:-('a','b','c','d')a Enter the room charge: 250 Enter the room numbers: 10 Details of hotel 2 Enter the hotel name:agni Enter the hotel address:kochi Enter the hotel grade:-('a','b','c','d')a Enter the room charge: 500 Enter the room numbers: 20 Details of hotel 3 Enter the hotel name:prithvi Enter the hotel address:pathanamthitta Enter the hotel grade:-('a','b','c','d')b Enter the room charge: 1000 Enter the room numbers:
  • 11. 43 5 Details of hotel 4 Enter the hotel name:solo Enter the hotel address:trivandrum Enter the hotel grade:-('a','b','c','d')c Enter the room charge: 100 Enter the room numbers: 30 Details of hotel 5 Enter the hotel name:sagar Enter the hotel address:trivandrum Enter the hotel grade:-('a','b','c','d')a Enter the room charge: 500 Enter the room numbers: 5 Search for specific hotels Enter the grade for hotel('a','b','c','d'):a Hotel names with specified GRADE in order of charge rudra 250.00 agni 500.00 sagar 500.00 Enter the maximum charge:300 Hotel names below the specified RATE. rudra 250.00 solo 100.00
  • 12. 44 Set 3 Q3 Define a structure named mea_class which include the following members: Roll number, Name, mark of 5 subjects. Write a program to calculate the aggregate percentage and the grade of each student, and print the details in a neat format. The constraint for grading is as follows: Aggregate % Grade >=95 A++ >=85 and <95 A+ >=80 and <85 A >=75 and <80 B++ >=70 and <75 B+ >=60 and <70 B >=50 and <60 C <50 F Program #include <stdlib.h> #include <stdio.h> #include <string.h> struct mca_class { int rollno; char name[40]; int mark[5]; float per;
  • 13. 45 char grade[3]; }; void read (struct mca_class *student,int n); void display(struct mca_class *student,int n); int main() { struct mca_class *student; int n; puts("Enter the number of students"); scanf("%d",&n); student = (struct mca_class*) malloc (n * sizeof(struct mca_class)); read (student,n); display (student,n); return 0 ; } void read (struct mca_class *student,int n) { int i,j; float total,per; char gr[3]; for(i=0;i<n;i++) {
  • 14. 46 fflush(stdin); printf("Student Roll No:"); scanf("%d",&(student+i)->rollno); fflush(stdin); printf("Enter the Student name:"); gets((student+i)->name); fflush(stdin); printf("Enter the mark of subjects out of 100 n"); total=0; for (j=0;j<5;j++) { printf("Enter the mark of subject %d:",j+1); scanf("%d",&(student+i)->mark[j]); total=total+(student+i)->mark[j]; } per=total/5; student[i].per=per; printf("%0.2f,",per); if (per>=95) strcpy(gr,"A++"); else if ((per>=85)&&(per<95)) strcpy(gr,"A+"); else if ((per>=80)&&(per<85)) strcpy(gr,"A"); else if ((per>=75)&&(per<80)) strcpy(gr,"B++"); else if ((per>=70)&&(per<75))
  • 15. 47 strcpy(gr,"B+"); else if ((per>=60)&&(per<70)) strcpy(gr,"B"); else if ((per>=50)&&(per<60)) strcpy(gr,"C"); else strcpy(gr,"F"); strcpy((student+i)->grade,gr); } } void display(struct mca_class *student,int n) { int i,j; if(student == NULL) { printf("ERROR !!! NULL pointer !!!n"); return; } else { printf("List of students:n"); printf("=========================n"); printf("Roll NotNametMark 1tMark 2tMark 3tMark 4tMark 5tPertGraden");
  • 16. 48 printf("=============================================== ==========================n"); for(i=0;i<n;i++) { printf("%dt%s",(student+i)->rollno,(student+i)- >name); for(j=0;j<5;j++) { printf("t%d",(student+i)->mark[j]); } printf("t%.2ft%sn",(student+i)->per,(student+i)- >grade); } printf("n"); } } Output Enter the number of students 5 Student Roll No:1 Enter the Student name:aakash Enter the mark of subjects out of 100 Enter the mark of subject 1:80 Enter the mark of subject 2:45 Enter the mark of subject 3:35 Enter the mark of subject 4:14
  • 17. 49 Enter the mark of subject 5:78 Student Roll No:2 Enter the Student name:binu Enter the mark of subjects out of 100 Enter the mark of subject 1:48 Enter the mark of subject 2:23 Enter the mark of subject 3:17 Enter the mark of subject 4:14 Enter the mark of subject 5:85 Student Roll No:3 Enter the Student name:eva Enter the mark of subjects out of 100 Enter the mark of subject 1:12 Enter the mark of subject 2:10 Enter the mark of subject 3:09 Enter the mark of subject 4:7 Enter the mark of subject 5:05 Student Roll No:4 Enter the Student name:joshi Enter the mark of subjects out of 100 Enter the mark of subject 1:45 Enter the mark of subject 2:99 Enter the mark of subject 3:98 Enter the mark of subject 4:96 Enter the mark of subject 5:93 Student Roll No:5 Enter the Student name:santhi
  • 18. 50 Enter the mark of subjects out of 100 Enter the mark of subject 1:78 Enter the mark of subject 2:99 Enter the mark of subject 3:91 Enter the mark of subject 4:85 Enter the mark of subject 5:23 List of students: ========================= Roll No Name Mark 1 Mark 2 Mark 3 Mark 4 Mark 5 Per Grade ========================================================= 1 aakash 80 45 35 14 78 50.40 C 2 binu 48 23 17 14 85 37.40 F 3 eva 12 10 9 7 5 8.60 F 4 joshi 45 99 98 96 93 86.20 A+ 5 santhi 78 99 91 85 23 75.20 B++
  • 19. 51 Set 3Q5 Define a structure named employee consisting of the following members: Employee ID, Name, Department, Basic Salary, DA (in %), HRA(in%). Write a program to prepare the pay-slip of the employees of a particular department, using array of structures. Program #include <stdlib.h> #include <stdio.h> #include <string.h> struct employee { int empid; char name[40]; char dept[40]; float basic; float da; float hra; float gross; }; void read (struct employee *emp,int n); void display(struct employee *emp,char* dept,int n); int main() {
  • 20. 52 struct employee *emp; int n; char dept[40]; puts("Enter the number of employees"); scanf("%d",&n); emp = (struct employee*) malloc (n * sizeof(struct employee)); read (emp,n); puts("Enter the dept name of employees whose pay slip is to be displayed: n"); fflush(stdin); gets(dept);; display (emp,dept,n); free(emp); return 0 ; } void read (struct employee *emp,int n) { int i; float da,hra; printf("Enter da rate: "); scanf("%f",&da);
  • 21. 53 printf("Enter hra rate: "); scanf("%f",&hra); for(i=0;i<n;i++) { printf("Enter employee ID: "); scanf("%d",&(emp+i)->empid); printf("Enter name of the employee: "); fflush(stdin); gets((emp+i)->name); printf("Enter Department name: "); fflush(stdin); gets((emp+i)->dept); printf("Enter Basic salary: n"); scanf("%f",&(emp+i)->basic); (emp+i)->da = ((emp+i)->basic*da)/100; (emp+i)->hra = ((emp+i)->basic*hra)/100; (emp+i)->gross = (emp+i)->basic + (emp+i)->da + (emp+i)->hra; } } void display(struct employee *emp,char* dept,int n) { int i,found =0;
  • 22. 54 if(emp == NULL) { printf("ERROR !!! NULL pointer !!!n"); return; } else { printf("nPay-slip of employees of department : %sn",dept); printf("n"); printf("Emp IDtNametBasictDAtHRAtGross Salaryn"); printf("=============================================== ===========n"); for(i=0;i<n;i++) { if(strcmp((emp+i)->dept,dept)==0) { printf("%dt%st%.2ft%.2ft%.2ft%.2fn",(emp+i)- >empid,(emp+i)->name,(emp+i)->basic,(emp+i)->da,(emp+i)->hra,(emp+i)- >gross); found =1; } } if(found ==0) printf("nPay-slips NOT FOUND for the requested Dept- %s!!!!!!!!n",dept); printf("n"); }
  • 23. 55 } Output Enter the number of employees 5 Enter da rate: 5 Enter hra rate: 10 Enter employee ID: 1 Enter name of the employee: sarun Enter Department name: it Enter Basic salary: 1000 Enter employee ID: 2 Enter name of the employee: sajan Enter Department name: sales Enter Basic salary: 2000 Enter employee ID: 3 Enter name of the employee: joby Enter Department name: it Enter Basic salary: 5000 Enter employee ID: 4 Enter name of the employee: ginu Enter Department name: it Enter Basic salary: 2000
  • 24. 56 Enter employee ID: 5 Enter name of the employee: shibu Enter Department name: marketing Enter Basic salary: 5400 Enter the dept name of employees whose pay slip is to be displayed: it Pay-slip of employees of department : it Emp ID Name Basic DA HRA Gross Salary ========================================================= 1 sarun 1000.00 50.00 100.00 1150.00 3 joby 5000.00 250.00 500.00 5750.00 4 ginu 2000.00 100.00 200.00 2300.00
  • 25. 57 Set 3 Q5Write a program to accept records of the different states using array of structures. The structure should contain state_name, population, literacy_rate and per_capita_income. Assume suitable data. Display the state whose literacy rate is highest and whose per capita income is highest. (use typedef in the program). Program #include <stdlib.h> #include <string.h> #include <stdio.h> typedef struct statedemography { char state_name[50]; long int population; float literacy_rate; float per_capita_income; }statedetails; void readstate(statedetails * , int ); void printstate(statedetails * , int); int main(void) { int n; statedetails *state;
  • 26. 58 printf("Enter the number of states: "); scanf("%d", &n); state = (statedetails*)malloc(sizeof(statedetails)*n); readstate(state, n); printstate(state, n); free(state); return 0; } void readstate(statedetails *state, int n) { int i; for(i=0;i<n;i++) { printf("Enter name of the state: n"); fflush(stdin); gets((state+i)->state_name); printf("nEnter population: n"); scanf("%ld",&(state+i)->population); printf("Enter literacy rate: n"); scanf("%f",&(state+i)->literacy_rate); printf("Enter per capita income: n");
  • 27. 59 scanf("%f",&(state+i)->per_capita_income); } } void printstate(statedetails *state, int n) { int i; if(state == NULL) { printf("ERROR !!! NULL pointer !!!n"); return; } else { float maxLiteracy, maxpercapIncome; i=0; maxLiteracy = (state+i)->literacy_rate; maxpercapIncome = (state+i)->per_capita_income; for(i=1;i<n;i++) { if ((state+i)->literacy_rate > maxLiteracy) maxLiteracy = (state+i)->literacy_rate; if ((state+i)->per_capita_income > maxpercapIncome)
  • 28. 60 maxpercapIncome = (state+i)->per_capita_income; } for(i=0;i<n;i++) { if ((state+i)->literacy_rate == maxLiteracy) printf("State %s",(state+i)->state_name); printf(" have Maximum literacy rate:%.2fn",maxLiteracy); } printf("n"); for(i=0;i<n;i++) { if ((state+i)->per_capita_income == maxpercapIncome) printf("State %s ",(state+i)->state_name); printf(" have Maximum per capita income:%.2fn",maxpercapIncome); } printf("n"); } }
  • 29. 61 Output Enter the number of states: 5 Enter name of the state: kerala Enter population: 15000 Enter literacy rate: 99 Enter per capita income: 5000 Enter name of the state: bihar Enter population: 58000 Enter literacy rate: 85 Enter per capita income: 1500 Enter name of the state: gujarat Enter population: 90000 Enter literacy rate: 45 Enter per capita income: 7400 Enter name of the state: punjab Enter population: 56000 Enter literacy rate: 23 Enter per capita income: 4800 Enter name of the state: goa Enter population: 96000 Enter literacy rate: 93 Enter per capita income: 5200 State kerala have Maximum literacy rate:99.00 State gujarat have Maximum per capita income:7400.00