In: Computer Science
PROBLEM: Write a C program that will produce the EXACT output shown below.
Use the data from the example below.
Candidates Subdivisions Totals
Aberdeen Brock Sahali
Audrey 600 800 800 2200
Brian 700 700 600 2000
Elizabeth 800 700 800 etc
Peter 400 450 300
Zachary 900 900 900
Totals 3400 etc etc
// C code for given requirements
#include<stdio.h>
int main()
{
const char
*names[]={"Audrey","Brain","Elizabeth","Peter","Zachary"};
const char *divisions[]={"Aberdeen","Brock","Sahali\n"};
int aberdeenvotes[]={600,700,800,400,900};
int brockvotes[]={800,700,700,450,900};
int sahalivotes[]={800,600,800,300,900};
int rowcount[5],total[3]={0},grandtotal=0,i;
//compute row total
for(i=0;i<5;i++)
rowcount[i]=aberdeenvotes[i]+brockvotes[i]+sahalivotes[i];
//compute column total
for(i=0;i<5;i++){
total[0]=total[0]+aberdeenvotes[i];
total[1]=total[1]+brockvotes[i];
total[2]=total[2]+sahalivotes[i];
}
//compute grandtotal
for(i=0;i<3;i++)
grandtotal+=total[i];
//printing output statements
printf("Candidates \t\t\t Subdivisions\t\t Totals\n");
printf("\t\t %s \t %s \t
%s",divisions[0],divisions[1],divisions[2]);
for(i=0;i<5;i++)
printf("\n%s \t%d \t\t %d \t\t %d \t\t
%d",names[i],aberdeenvotes[i],brockvotes[i],sahalivotes[i],rowcount[i]);
//column totals and grandtotal print
statement
printf("\nTotals: ");
for(i=0;i<3;i++)
printf(" \t%d\t",total[i]);
//print grand total
printf("\t%d",grandtotal);
}