Guest User

Untitled

a guest
Dec 5th, 2019
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string.h>
  3. #include <math.h>
  4. using namespace std;
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. const int lvet=50;
  8. float numeri[lvet];
  9. float magg[lvet];
  10. float temp;
  11. float somma;
  12. float media;
  13. float dif;
  14. int n,j,i;
  15.  
  16.  
  17. void carica(){
  18. do{cout<<"Quanti numeri vuoi inserire?[maggiori di zero e pari]"<<endl;
  19. cin>>n;}while (lvet<n>0 || n%2!=0);
  20. for (i=0;i<n;i++){
  21. cout<<"Inserisci "<<i+1<<"° numero"<<endl;
  22. cin>>numeri[i];
  23. }
  24. }
  25.  
  26. void ordinamento(){
  27. j=n-1;
  28.  
  29. while (j>1){
  30. i=0;
  31. while (i<j){
  32. if(numeri[i]>numeri[i+1]){
  33. temp=numeri[i];
  34. numeri[i]=numeri[i+1];
  35. numeri[i+1]=temp;
  36.  
  37. }
  38. i=i+1;
  39.  
  40. }
  41. j--;
  42. }
  43. }
  44.  
  45. void stampa(){
  46. cout<<endl<<endl;
  47. for (i=0;i<n;i++){
  48. cout<<numeri[i]<<endl<<endl;
  49. }}
  50. void differenza(){
  51. for (i=0;i<n;i++){
  52. somma=somma+numeri[i];
  53. } media=somma/n;
  54. cout<<"La media e': "<<media<<endl;
  55. for (int i=0;i<n;i++){
  56. dif=abs(numeri[i]-media);
  57. cout<<"Il distacco della media del "<<i+1<<"° numero e' "<<dif<<endl;
  58. }cout<<endl<<endl;
  59. }
  60. void coppie(){
  61. cout<<endl<<endl;
  62. for (i=0;i<n;i=i+2){
  63. somma=numeri[i]+numeri[i+1];
  64. cout<<"La somma del "<<i+1<<"° numero e del "<<i+2<<"° numero e': "<<somma<<endl;
  65. }cout<<endl<<endl;
  66. }
  67.  
  68. void stampa_inverse(){
  69. cout<<endl<<endl<<"Ordinamento da magg a min:"<<endl;
  70. for (i=n-1;i>=0;i--){
  71. cout<<numeri[i]<<endl;
  72. }
  73. cout<<endl<<endl;}
  74.  
  75. void magg_100(){
  76. j=0;
  77. for (i=0;i<n;i++){
  78. if(numeri[i]>100){
  79. magg[j]=numeri[i];
  80. j++;
  81. }
  82. }
  83.  
  84. }
  85.  
  86. void stampa_magg(){
  87. if(magg[0]>0){
  88. cout<<"I numeri maggiori di 100 sono:"<<endl;
  89. for (i=0;i<j;i++){
  90. cout<<magg[i]<<endl;}
  91. }}
  92.  
  93. int main(int argc, char** argv) {
  94. carica();
  95. ordinamento();
  96. stampa();
  97. differenza();
  98. coppie();
  99. stampa_inverse();
  100. magg_100();
  101. stampa_magg();
  102. system("pause");
  103. return 0;
  104. }
RAW Paste Data