fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. float valor(float *k, int t){
  5. float soma = 0;
  6. for (int i = 0; i < t; i++) soma += k[i];
  7. return soma;
  8. }
  9.  
  10. int main() {
  11. int quant;
  12. printf("Digite a quantidade: ");
  13. scanf("%d", &quant);
  14. float *vTotal = malloc(quant * sizeof(float));
  15. for (int i = 0; i < quant; i++){
  16. printf("Digite o valor %d: ", i + 1);
  17. scanf("%f", &vTotal[i]);
  18. }
  19. float teste = valor(vTotal, quant);
  20. printf("\n %.2f", teste);
  21. free(vTotal);
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/148160/101
Success #stdin #stdout 0s 4380KB
stdin
3
12
8
16
stdout
Digite a quantidade: Digite o valor 1: Digite o valor 2: Digite o valor 3: 
 36.00