Advertisement
Sayukoo

[Funkcja] Obliczanie Sumy tablica

Oct 29th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. float s(int x)
  4. {
  5.  
  6.     float *liczba,suma;
  7.     int i;
  8.  
  9.     liczba =(float*)malloc(x*sizeof(int));
  10.     for(i=0;i<x;i++)
  11.     {
  12.         printf("Podaj %d liczbe: ",i+1);
  13.         scanf("%f",&liczba[i]);
  14.          suma=suma+liczba[i];
  15.     }
  16.     return suma;
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22.     int x;
  23.     printf("Napisz ilosc liczb ktora chcesz zsumowac: ");  scanf("%d",&x);
  24.     printf("\n Suma wynosi : %.2f",s(x));
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement