Advertisement
Guest User

Untitled

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