Define a structure called ParliamentMember, consisting of the following fields: Member Name, Region Name, Party Name and Percentage of vote achieved. Create an array of structure to hold records of 20 such Member details and then write C code to read these records and find out the record of those members who has won from particular region
#include<string.h>
#define MAX 20
struct ParliamentMember
{
char MemberName[100];
char RegionName[100];
char PartyName[100];
int PercentageOfVote;
}m[MAX];
int main(void)
{
int i, max=0, index;
char region[100];
for(i=0; i<MAX; i++)
{
printf("\nEnter Member Name: ");
scanf("%s", m[i].MemberName);
printf("Enter region name: ");
scanf("%s", m[i].RegionName);
printf("Enter party name: ");
scanf("%s", m[i].PartyName);
printf("Enter Percentage Of Vote: ");
scanf("%d", &m[i].PercentageOfVote);
}
printf("\n\nEnter the name of region: ");
scanf("%s",region);
for(i=0; i<MAX; i++)
{
if ( strcmp(m[i].RegionName,region) == 0)
{
if(m[i].PercentageOfVote > max)
{
max= m[i].PercentageOfVote;
index=i;
}
}
}
printf("\n/------------------------------------------------------\n");
printf("Member Name: %s\n", m[index].MemberName);
printf("Party name: %s\n", m[index].PartyName);
printf("Percentage of vote: %d\n", m[index].PercentageOfVote);
printf("\n/------------------------------------------------------\n");
return 0;
}
#define MAX 20
struct ParliamentMember
{
char MemberName[100];
char RegionName[100];
char PartyName[100];
int PercentageOfVote;
}m[MAX];
int main(void)
{
int i, max=0, index;
char region[100];
for(i=0; i<MAX; i++)
{
printf("\nEnter Member Name: ");
scanf("%s", m[i].MemberName);
printf("Enter region name: ");
scanf("%s", m[i].RegionName);
printf("Enter party name: ");
scanf("%s", m[i].PartyName);
printf("Enter Percentage Of Vote: ");
scanf("%d", &m[i].PercentageOfVote);
}
printf("\n\nEnter the name of region: ");
scanf("%s",region);
for(i=0; i<MAX; i++)
{
if ( strcmp(m[i].RegionName,region) == 0)
{
if(m[i].PercentageOfVote > max)
{
max= m[i].PercentageOfVote;
index=i;
}
}
}
printf("\n/------------------------------------------------------\n");
printf("Member Name: %s\n", m[index].MemberName);
printf("Party name: %s\n", m[index].PartyName);
printf("Percentage of vote: %d\n", m[index].PercentageOfVote);
printf("\n/------------------------------------------------------\n");
return 0;
}
Comments
Post a Comment