Advertisement
lukasd

zadanie 2 poprawa kolokwium 2016

Feb 15th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. int func(int n,int x, int* arr)
  2. {
  3.     int suma = 0;
  4.     for (int i = 0; i < n; i++)
  5.     {
  6.         if (arr[i] % x != 0)
  7.         {
  8.             arr[i] = arr[i] * arr[i];
  9.             suma += arr[i];
  10.         }
  11.     }
  12.     return suma;
  13. }
  14. void kolos1()
  15. {
  16.     int n;
  17.     int x;
  18.     scanf("%d", &n);
  19.     scanf("%d", &x);
  20.  
  21.     int *arr = (int*)malloc(sizeof(int)*n);
  22.     for (int i = 0; i < n; i++)
  23.     {
  24.         arr[i] = rand() % 100;
  25.     }
  26.     for (int i = 0; i < n; i++)
  27.     {
  28.         printf("%d ", arr[i]);
  29.     }
  30.  
  31.     printf("%d",func(n, x, arr));
  32.     free(arr);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement