0
#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.

Niafo
  • 1
  • 5
    What are parallel arrays? – Vlad from Moscow Apr 30 '21 at 19:51
  • This seems to be an assignment in some class. Code looks familiar with [this question](https://stackoverflow.com/questions/67338683/where-is-the-parallel-array-in-this-c-code) Didn't you get some introduction to the topic before getting homework assignment? Or is that other question from another account of you? – Gerhardh Apr 30 '21 at 19:57
  • It appears that this code could benefit from the use of structs to organize data that should go together rather than using parallel arrays. Parallel arrays were popular in early Fortran programming when the only data structure supported by Fortran was arrays. – Jim Rogers Apr 30 '21 at 20:01
  • @Vlad from Moscow - Parallel arrays are an old technique using multiple arrays to store associated data. For instance, one array holds the name of a candidate while another array holds the votes received by a candidate. A more modern approach would be to create a struct to hold the name and the votes received. One might then create an array of those structs to represent all the candidates and their votes. – Jim Rogers Apr 30 '21 at 20:06

0 Answers0