Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream> /* File: construction-destruction-order.cpp */
  2. using namespace std;
  3.  
  4.  
  5. int main(){
  6. int k=0;
  7. int max=0;
  8. int min=0;
  9. double sum=0;
  10. int temp=0;
  11. int ntemp=0;
  12. do{
  13. cout<<"please input a number k"<<endl;
  14. cin>>k;
  15. }while(k<=0);
  16. cout<<"the number of positive integers is "<<k<<endl;
  17. cout<<"please input "<<k<<" strictly increasing positive integers"<<endl;
  18. int i=k;
  19. while(i>0){
  20. cin>>ntemp;
  21. if(ntemp<temp){
  22. cout<<"please input strictly increasing positive integers"<<endl;
  23. while(ntemp<temp){
  24. cout<<"please input:"<<endl;
  25. cin>>ntemp;
  26. }
  27. cout<<"after changing, input increasing ok"<<endl;
  28. }
  29. temp=ntemp;
  30. if(temp>max||i==k){
  31. max=temp;
  32. }
  33. if(temp<min||i==k){
  34. min=temp;
  35. }
  36. sum+=temp;
  37. i--;
  38. }
  39. double avg = sum/k;
  40. cout<<"total input increasing ok"<<endl;
  41. cout<<"min: "<<min<<" max:"<<max<<" average: "<<avg<<endl;
  42. return 0;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement