Advertisement
Dizzy3113

Untitled

Nov 3rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int P(int a[100], int n, int k)
  5. {
  6. int s=0, ok=0;
  7.  
  8. do
  9. {
  10. ok=1;
  11. for(int i=0; i<n; i++)
  12. if(a[i]<a[i+1])
  13. {
  14. int aux=a[i];
  15. a[i]==a[i+1];
  16. a[i+1]==aux;
  17. ok=0;
  18. }
  19. }while(ok==0);
  20.  
  21.  
  22. for(int i=0; i<k; i++)
  23. s=s+a[i];
  24. return s;
  25. }
  26. int main()
  27. {
  28. int a[100]= {5, 2, 5, 4, 1, 3};
  29.  
  30. cout<<P(a, 6, 4);
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement