Where are the parallel arrays in this c code?

110 Views Asked by At
#include <stdio.h>
#include<math.h>
int main()
{
int no_candiates;
int no_regions;
int details[100][100];//for the votes in each regions
char names[100][100];//for candidate names
int total[100];//total votes of each candidate
int percentage[100];//percentage of votes for each candidate
int i,j;
int sum;
float p;
int total_votes=0;//total votes of all candidates
int winner;
int largest;
int winner_region=0;
//reading number of candidates
printf("Enter number of candidates: ");
scanf("%d",&no_candiates);
//reading number of regions
printf("Enter number of regions: ");
scanf("%d",&no_regions);
//reading votes for each candidate in each region
for(i=0;i<no_candiates;i++)
{
    printf("Enter the last name of candidate : ");
    scanf("%s",names[i]);
    for(j=0;j<no_regions;j++)
    {
        printf("Enter number of votes for region %d : ",j+1);
        scanf("%d",&details[i][j]);
    }
}
//finding total votes for each candidate

for(i=0;i<no_candiates;i++)
{
    sum=0;
    for(j=0;j<no_regions;j++)
    {
        sum=sum+details[i][j];//calculating total
    }
    total[i]=sum;
    total_votes=total_votes+sum;//total of all candidates
}
//calculating percentage of votes
for(i=0;i<no_candiates;i++)
{
    p=(float)total[i];
    p=(float)p/total_votes*100;
    percentage[i]=round(p);//rounding to integer
}
//finding the winner
largest=total[0];
winner=0;//index of the winner in the array
for(i=1;i<no_candiates;i++)
{
    if(largest<total[i])
    {
        largest=total[i];
        winner=i;
    }
    
}
//finding the region in which highest number of votes obtained
largest=details[winner][0];
winner_region=0;//index of the region
for(i=1;i<no_regions;i++)
{
    if(largest<details[winner][i])
    {
        largest=details[winner][i];
        winner_region=i;
    }
}
//displaying the details
printf("candidate\t");
for(i=0;i<no_regions;i++)
printf("Region %d\t",i+1);
printf("total\t %% of total Votes\n");
printf("--------------------------------------------------------------------------------------------\n");
for(i=0;i<no_candiates;i++)
{
    printf("%s\t",names[i]);
    for(j=0;j<no_regions;j++)
    {
        printf("%d\t\t",details[i][j]);
    }
    printf("%d\t%d",total[i],percentage[i]);
    printf("\n");
}
printf("\nTotal\t\t\t\t\t\t\t\t%d\n",total_votes);
printf("\nThe winner of the election is %s\n",names[winner]);
printf("%s has got maximum votes in region %d",names[winner],winner_region+1);
return 0;
}

Here is a c code that has various arrays, some are one dimensional arrays and some are two dimensional arrays but I can not figure out where are the parallel arrays.

The parallel array/s might be in the beginning of the program but I can not seem to recognize them so please any help is greatly appreciated.

I need help finding parallel arrays in this code above.

Thanks in advance.

0

There are 0 best solutions below