0
With the following question to solve, I need to create a progression in c that le n positive integers compute and display the artimetica media of these, the halting condition of this loop and the insertion of a negative number, I made the following code, but always it returns as result 1 no matter the values used(yes I’ve already set everything as float 1 anyway, ta duplicated nothing, there’s nothing here similar to this problem), what I’m doing wrong?
#include <stdio.h>
#include <stdlib.h>
int main(){
int n,s,c;
float m;
do{
printf("Digite um valor: ");
scanf("%d", &n);
s= s+n;
c++;
}while(n>0);
m=s/c;
printf("A media dos valores digitados foi: %d", m);
return 0;
}
I’ve already edited the question.
– user127541
Make the appropriate conversion: m = (float)s / c;
– anonimo
It did nothing to make this conversion the result displayed yet and 1
– user127541
You forgot to initialize the c and s variables with zero.
– anonimo
Gave the same thing
– user127541
in the
printf
has%d
and to write the value of m is%f
– IanMoone
and finally it was, thank you very much, I was going to spend the whole day pondering on the same problem
– user127541