#include<stdio.h>
#include<stdlib.h>
typedef struct Estatisticas {
float soma;
float media;
float maior;
int acima_media;
} Estatisticas;
float * ler_debitos( int qnt) {
int i;
float * debitos
= malloc ( qnt
* sizeof ( float ) ) ; for ( i = 0 ; i < qnt; i++ ) {
printf ( "informe o valor em debito da %d%c pessoa\n " , i
+ 1 , 167 ) ; scanf ( "%f" , & debitos
[ i
] ) ; }
return debitos;
}
Estatisticas totalizar( float * debitos, int qnt) {
Estatisticas totais = { 0 } ;
int i;
for ( i = 0 ; i < qnt; i++ ) {
totais.soma += debitos[ i] ;
if ( debitos[ i] > totais.maior ) {
totais.maior = debitos[ i] ;
}
}
totais.media = totais.soma / qnt;
for ( i = 0 ; i < qnt; i++ ) {
if ( debitos[ i] > totais.media ) {
totais.acima_media ++;
}
}
return totais;
}
int main( ) {
int qnt;
printf ( "informe a quantidade de pessoas a serem fiscalizadas: \n " ) ;
float * debitos = ler_debitos( qnt) ;
Estatisticas totais = totalizar( debitos, qnt) ;
printf ( "a soma de todos os valores: %f\n " , totais.
soma ) ; printf ( "a media dos valores: %f\n " , totais.
media ) ; printf ( "o maior valor foi: %f\n " , totais.
maior ) ; printf ( "a quantidade de pessoas acima da media foi: %d\n " , totais.
acima_media ) ;
int i;
for ( i = 0 ; i < qnt; i++ ) {
printf ( " %d valor : %f\n " , i
+ 1 , debitos
[ i
] ) ; }
return 0 ;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+Cgp0eXBlZGVmIHN0cnVjdCBFc3RhdGlzdGljYXMgewogICAgZmxvYXQgc29tYTsKICAgIGZsb2F0IG1lZGlhOwogICAgZmxvYXQgbWFpb3I7CiAgICBpbnQgYWNpbWFfbWVkaWE7Cn0gRXN0YXRpc3RpY2FzOwoKZmxvYXQqIGxlcl9kZWJpdG9zKGludCBxbnQpewogICAgaW50IGk7CiAgICBmbG9hdCAqZGViaXRvcyA9IG1hbGxvYyAocW50ICogc2l6ZW9mKGZsb2F0KSk7C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