Advertisement
informaticage

ACE C++ Esercizio 2

Apr 14th, 2021
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main() {
  5.   // n1 ed n2 sono gli estremi dell'intervallo di numeri da sommare
  6.   int n1, n2;
  7.   cout << "Inserire n1, n2 (n2 >= n1): ";
  8.   cin >> n1 >> n2;
  9.  
  10.   int i = n1, somma = 0;
  11.   while (i <= n2) {
  12.     somma = somma + i;
  13.     i++;
  14.   }
  15.  
  16.   cout << "La somma dei numeri compresi tra n1 ed n2 e': " << somma;
  17.   return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement