Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main(){
- long long a,b,w = 0;
- cout << "Podaj pierwsza liczbe: ";
- while(!(cin >> a)){
- cin.clear();
- string str;
- cin >> str;
- cout << "Blad: \"" << str << "\" nie jest liczba" << endl;
- }
- cout << "\nPodaj druga liczbe: ";
- while(!(cin >> b)){
- cin.clear();
- string str;
- cin >> str;
- cout << "Blad: \"" << str << "\" nie jest liczba" << endl;
- }
- //Sprawdzenie czy "a" jest większe niż "b"
- if(a>b){
- long long a0 = a;
- a = b;
- b = a0;
- }
- while(a < b+1)w += a++; //Główna operacja programu, czyli sumowanie liczb
- cout << "\nSuma liczb z tego zakresu wynosi: " << w << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement