GerexD

GY29_5,14

Mar 6th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. 14
  2.  
  3. #include <iostream>
  4. #include <limits.h>
  5. ///14. Adott egy egész számokat tartalmazó sorozat. Szúrjuk be a sorozat
  6. ///legkisebb eleme elé a pozitív számok összegét.
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. int a[50],n,k,min=INT_MAX,o=0;
  12. cout<<"N ";cin>>n;
  13. for(int i=1;i<=n;i++)cin>>a[i];
  14.  
  15. for(int i=1;i<=n;i++){
  16. if(a[i]%2==0)o=o+a[i];
  17. if(a[i]<min) min=a[i];}
  18. for(int i=1;i<=n;i++)
  19. if(a[i]==min) k=i;
  20. for(int i=n;i>=k;i--) a[i+1]=a[i];
  21. a[k]=o;
  22. n++;
  23. for(int i=1;i<=n;i++) cout<<a[i]<<" ";
  24. return 0;
  25. }
  26.  
  27. +++++++++++++++++++++++++++++
  28. 5
  29. //Szúrjuk be egy n elemű egész sorozat minden páratlan értékű eleme után az illető szám ellentettjét.
  30. #include <iostream>
  31.  
  32. using namespace std;
  33.  
  34. int main()
  35. {
  36. int n,a[50];
  37. cout << "n=" << endl;
  38. cin>>n;
  39. for(int i=1; i<=n; i++)
  40. cin>>a[i];
  41. int i=1;
  42. while(i<=n)
  43.  
  44. {
  45.  
  46. if(a[i]%2!=0)
  47. {
  48. ///beszuras i+1 poz
  49. for(int j=n;j>=i+1;j--)
  50. a[j+1]=a[j];
  51. a[i+1]=-a[i];
  52. n++;
  53. i=i+2;
  54. }
  55. else i++;
  56. }
  57. for(int i=1;i<=n;i++)
  58. cout<<a[i]<<" " ;
  59.  
  60.  
  61.  
  62. return 0;
  63. }
  64. +++++++++++
Advertisement
Add Comment
Please, Sign In to add comment