-
-
Save anonymous/6726f9eb5d8ef39fffba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
FILE *ifp; | |
ifp = fopen("votes.txt","r"); | |
int ROWS,COLS, max=0, stateNumber=1; | |
fscanf(ifp, "%d", &ROWS); | |
fscanf(ifp, "%d", &COLS); | |
int k; | |
int voting[ROWS][COLS],i,j; | |
char party[ROWS]; | |
printf("Election Results\n"); | |
printf("---------------------------------------\n"); | |
for(i=0; i<ROWS; i++) | |
{ party[i]=65+i; | |
for(j=0; j<COLS; j++) | |
{ | |
fscanf(ifp, "%d", &voting[i][j]); | |
} | |
} | |
int statecounters [ROWS]; | |
for (i=0;i<ROWS;i++) | |
{ | |
statecounters[i]=0; | |
} | |
for (j=0; j<COLS;j++) { | |
for (i=0; i<ROWS; i++){ | |
if (voting[i][j] > max){ | |
max = voting[i][j]; | |
k = i; | |
} | |
} | |
max=0; | |
statecounters[k]+=1; | |
printf("State%d was won by party %c\n", j, party[k]); | |
} | |
printf("Election Results\n"); | |
printf("---------------------------------------\n"); | |
printf("Party #states won\n"); | |
int h,p=0; | |
int states_won; | |
max=0; | |
for (h=0; h<=ROWS-1; h++){ | |
if(statecounters[h]>max){ | |
p=h; | |
max = statecounters[h]; | |
} | |
printf("%c %d\n", party[h], statecounters[h]); | |
} | |
printf("Party %c has won the election, winning %d states\n",party[p],statecounters[p]); | |
fclose(ifp); | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment