lambdabot

Untitled

Oct 31st, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. programa em common lisp
  2.  
  3. (defun s(n)
  4. "Obeter um valor e o soma a cada iteracao no loop"
  5. (loop repeat n do (setq a(read))
  6. sum a))
  7.  
  8. ---------------------------------------
  9. programa em C
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. void recebeESoma(int max){
  15. // essa funcao recebe o tamanho maximo para o vetor, os valores para formar o vetor e depois os soma
  16.  
  17. int *v = (int* ) malloc (max * sizeof(int)); // meu vetor
  18. int soma = 0;
  19.  
  20. // recebendo valores no meu vetor e ja fazendo a soma
  21. for (int i = 0; i < max; i++){
  22. scanf("%d", &v[i]);
  23. soma += v[i];
  24. }
  25. free(v);
  26. printf("%d", soma);
  27. }
  28.  
  29. int main() {
  30. int n;
  31.  
  32. // recebendo tamanho maximo para meu vetor
  33. scanf("%d", &n);
  34. // passo N para a funcao soma
  35. recebeESoma(n);
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment