FedeBarto

INFORMATICA 24.03.17

Mar 23rd, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.51 KB | None | 0 0
  1. NUMERO PIÙ GRANDE TRA DUE NUMERI
  2. #include <iostream>
  3. using namespace std;
  4. int main() {
  5.     int n1,n2;
  6.     cout << "Inserisci un primo numero:\n";
  7.     cin >> n1;
  8.     cout << "Inserisci un secondo numero:\n";
  9.     cin >> n2;
  10.     if (n1>n2)
  11.       cout<<"il numero più grande tra questi due è: "<<n1;
  12.     if (n2>n1)
  13.       cout<<"il numero più grande tra questi due è: "<<n2;
  14.     if (n1==n2)
  15.       cout<<"il numero più grande tra questi due è: "<<n1;
  16.   return 0;
  17. }
  18.  
  19. PREZZO CON IVA, SCONTATO SOPRA I 100 EURO
  20. #include <iostream>
  21. using namespace std;
  22. int main() {
  23.   float prezzo;
  24.    cout << "Dammi il prezzo senza IVA: \n";
  25.    cin >> prezzo;
  26.    if (prezzo>100)
  27.    {cout<<"Essendo il prezzo maggiore di 100 euro meriti uno sconto del 35%: \n";
  28.      prezzo=prezzo*65/100;
  29.      cout<<prezzo<<"\n";
  30.      cout<<"Pur essendo scontato, a questo prezzo va aggiunta l'IVA: \n";
  31.    prezzo=prezzo*120/100;}
  32.    else
  33.   { cout<<"A questo prezzo va aggiunta l'IVA: \n";
  34.    prezzo=prezzo*120/100;}
  35.   cout << prezzo;
  36.   return 0;
  37. }
  38.  
  39. ORDINAZIONE CRESCENTE DI TRE NUMERI
  40. #include <iostream>
  41. using namespace std;
  42. int main() {
  43.   int a,b,c;
  44.     cout << "Inserisci tre numeri diversi e te li ordinerò!\n";
  45.     cout << "Primo numero:\n";
  46.     cin>>a;
  47.     cout << "Secondo numero:\n";
  48.     cin>>b;
  49.     cout << "Terzo numero:\n";
  50.     cin>>c;
  51.     if (a<=b and a<=c)
  52.       {cout<<a<<"-";
  53.         if (b<=c)
  54.           {cout<<b<<"-";
  55.           cout<<c;}
  56.            else
  57.             {cout<<c<<"-";
  58.             cout<<b;}
  59.       }
  60.       else
  61.     {if (b<=a and b<=c)
  62.       {cout<<b<<"-";
  63.         if (a<=c)
  64.           {cout<<a<<"-";
  65.           cout<<c;}
  66.            else
  67.             {cout<<c<<"-";
  68.             cout<<a;}
  69.       }
  70.       else
  71.      {if (c<=b and c<=a)
  72.       {cout<<c<<"-";
  73.         if (b<=a)
  74.           {cout<<b<<"-";
  75.           cout<<a;}
  76.            else
  77.             {cout<<a<<"-";
  78.             cout<<b;}
  79.       }}}
  80.    return 0;
  81.   }
  82.  
  83. ORDINAZIONE CRESCENTE DI TRE NUMERI IMMESSI OBBLIGATORIAMENTE UGUALI
  84. #include <iostream>
  85. using namespace std;
  86. int main() {
  87.   int a,b,c,max,med,min;
  88.     cout << "Inserisci tre numeri diversi e te li ordinerò!\n";
  89.     cout << "Primo numero:\n";
  90.     cin>>a;
  91.     do {cout << "Secondo numero:\n";
  92.     cin>>b;}
  93.     while (a==b);
  94.     /* o si può anche fare:
  95.     cout << "Secondo numero:\n";
  96.     cin>>b;
  97.     while (a==b)
  98.     {cout << "Il secondo numero deve essere diverso:\n";<--!con la possibilità di
  99.     cambiare la scritta che nel primo caso rimaneva sempre la stessa!
  100.     cin>>b; }*/
  101.     do {cout << "Terzo numero:\n";
  102.     cin>>c;}
  103.     while (b==c or a==c);
  104.  if (a>b)
  105.   max=a;
  106.     else
  107.   max=b;
  108. if (c>max)
  109.   max=c;
  110.  
  111. if (a<b)
  112.   min=a;
  113.     else
  114.   min=b;
  115. if (c<min)
  116.   min=c;
  117.  
  118.   if (a>min and a<max)
  119.   med=a;
  120.   else if (b>min and b<max)
  121.   med=b;
  122.   else
  123.   med=c;
  124.   cout<<min<<"-"<<med<<"-"<<max;
  125.  
  126.   return 0;
  127.   }
  128.  
  129. CONTO ALLA ROVESCIA CON FUNZIONE FOR
  130. #include <iostream>
  131. using namespace std;
  132. int main() {
  133.   for (int i=100;i>0;i--)
  134.   cout<<i<<endl;
  135.    
  136.   cout<<"BOOM!!!";
  137.   return 0;
  138.  
  139.   }
  140.  
  141. TABELLINE CON FUNZIONE FOR
  142. #include <iostream>
  143. using namespace std;
  144. int main() {
  145.   int a,b,h,w;
  146.   w=-1;
  147.   cout<<"Dimmi un numero e ti dirò la tabellina:";
  148.   cin>>a;
  149.   for (int i=1;i<11;i++)
  150.   cout<<a<<" * "<<i<<" = "<<a*i<<"\n";
  151.   return 0;
  152. }
  153.  
  154. DISEGNA RETTANGOLO, PARALLELOGRAMMA, TRIANGOLO CON FUNZIONE FOR
  155. (Il triangolo non funziona perfettamente, è stato fatto da me
  156. quindi potrebbe essere diverso da quello spiegato dal prof)
  157. #include <iostream>
  158. using namespace std;
  159. int main()
  160. {
  161.   int b,h,w,q;
  162.   cout<<"Dimmi la misura della base e dell'altezza di un rettangolo e te lo disegnerò:\n"<<"Base:";
  163.   cin>>b;
  164.   cout<<"Altezza:";
  165.   cin>>h;
  166.   cout<<"\n";
  167.   for (int i=0; i<h;i++)
  168.     { /*for (int i=0; i<b;i++)
  169.       cout<<"r";*/
  170.       for (int i=w; i<(b+h)-1;i++)
  171.         cout<<" ";
  172.       for (int i=0; i<b;i++)
  173.       cout<<"○ ";
  174.       cout<<"\n";}
  175.   cout<<"\n";
  176.  
  177.   w=-1;
  178.   for (int i=0; i<h;i++)
  179.     { /*for (int i=0; i<b;i++)
  180.       cout<<" ";*/
  181.       w++;
  182.       for (int i=w; i<(b+h)-1;i++)
  183.         cout<<" ";
  184.       q--;
  185.       for (int i=0; i<b;i++)
  186.       cout<<"○ ";
  187.       cout<<"\n";}
  188.   cout<<"\n";
  189.  
  190.   w=-1;
  191.   q=b;
  192.   for (int i=0; i<h;i++)
  193.     { /*for (int i=0; i<b;i++)
  194.       cout<<" ";*/
  195.       w++;
  196.       for (int i=w; i<(b+h)-1;i++)
  197.         cout<<" ";
  198.       q--;
  199.       for (int i=q; i<b;i++)
  200.         cout<<"o ";
  201.       cout<<"\n";}
  202.   cout<<"\n"<<"Federico Bartolini SRL";
  203.  return 0;
  204. }
Advertisement
Add Comment
Please, Sign In to add comment