fork download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. int funkcja(int n, int tab[])
  9. {
  10. int suma = 0;
  11. for(int i = 0; i < n; i++)
  12. {
  13. suma += pow(tab[i], 2);
  14. }
  15.  
  16. return suma;
  17. }
  18.  
  19. int main()
  20. {
  21. srand(time(NULL));
  22.  
  23. int tab[10];
  24. int n = sizeof(tab)/sizeof(tab[0]);
  25.  
  26. for(int i = 0; i < n; i++)
  27. {
  28. tab[i] = rand() % 100;
  29. cout << tab[i] << ' ';
  30. }
  31. cout << endl;
  32.  
  33. cout << funkcja(n, tab) << endl;
  34. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0 31 0 64 10 89 92 28 69 82 
33811