Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int *PierwszaUjemna(int t[], int n){
  6. for(int i = 0; i < n; i++){
  7. if(t[i] < 0)
  8. return &(t[i]);
  9. }
  10. return NULL;
  11. }
  12.  
  13. int SumaUjemnych(int t[], int n){
  14. int SumaUj = *PierwszaUjemna(t, n);
  15.  
  16. for(int i = 0; i < n; i++){
  17. if(PierwszaUjemna(t+i, i+1) != NULL)
  18. SumaUj += *PierwszaUjemna((t+i), n);
  19. t++;
  20. }
  21.  
  22. return SumaUj;
  23. }
  24.  
  25. int main() {
  26. int t[8] = {1,-2,3,-4,-5,1,-4,3};
  27.  
  28. cout << "Pierwsza ujemna: " << *PierwszaUjemna(t, 8) << endl;
  29.  
  30. int xx = SumaUjemnych(t, 8);
  31. cout << "Suma ujemnych: " << xx << endl;
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement