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;
}

这是具有各种数组的 ac 代码,有些是一维数组,有些是二维数组,但我不知道并行数组在哪里。

并行数组可能在程序的开头,但我似乎无法识别它们,因此非常感谢任何帮助。

我需要帮助在上面的代码中找到并行数组。

提前致谢。

4

0 回答 0