Hi. My program is supposed to find the average & mode of a set of 6 integers. This is what I have:
PHP Code:
#include<stdio.h>
int main()
{
int temp[6], i, avg, mode;
printf("Enter 6 integers: *REMEMBER TO PRESS ENTER BETWEEN EACH INTEGER!* ");
for(i=0; i<6; i++){
scanf("%d", &temp[i]);
}
/*average*/
avg = 0;
for(i=0; i<6; i++){
avg = avg+temp[i];}
printf("Average temperature: %d\n", avg/6);
/*mode*/
for(i=0; i<6; i++){
if(temp[i]== temp[i+1]){
mode=temp[i];
}
else{
mode=0;}
}
printf("Mode is: %d\n", mode);
return 0;
}
The problem is that if there should be two modes(ex. 2, 4, 8, 4, 6, 8) it will only display one of them. Any advice how to correct this problem is greatly appreciated.
Thank You.