Hello friends,
I am trying to make a simple average function but the resukts are faulty
say i enter 45 ,51 ,23 for 3 numbers but average shows 39.00 instead of 39.66
Code:
#include <stdio.h>#include <string.h>
#include <stdlib.h>
int main(){
average();
return 0;
}
void average(){
int a,b,c;
int total;
float avg = 0;
printf("\nEnter 3 numbers: ");
scanf("\n %d %d %d",&a,&b,&c);
total = a+b+c;
printf("Sum of 3 numbers is %d",total);
avg = total/3;
printf("\nAverage of 3 numbers is %.2f",avg);
return avg;
}