Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int num, num2 = 0, sum = 0;
- vector <int> nums = {};
- cout << "Enter a number between 100 and 999: ";
- cin >> num;
- cout << endl;
- if (num < 100 || num > 999)
- {
- cerr << "Invalid input, try again!" << endl;
- return 1;
- }
- cout << "Reversed number: " << endl;
- while (num>0)
- {
- num2 = num % 10;
- num = num / 10;
- sum += num2;
- nums.push_back(num2);
- cout << num2;
- }
- cout << endl;
- cout << "Stotici desetici edenici: " << endl;
- reverse(nums.begin(), nums.end());
- for ( int i = 0; i < 3; i++)
- {
- cout << nums[i] << " ";
- }
- cout << endl<< "Sumata na cifrite na chisloto e: "<< sum << endl;
- if (sum % 2 == 0) cout << "Deli se na 2!" << endl;
- if (sum % 3 == 0) cout << "Deli se na 3!" << endl;
- if (sum % 5 == 0) cout << "Deli se na 5!" << endl;
- cout << "Ne se deli na 2,3 i 5!";
- }
- //Да се напише програма, която подканва потребителя да въведе число в интервала [100,999], след което да се изведат
- //на отделни редове единиците, десетиците и стотиците на въведеното число. Да се изведе сумата на цифрите на числото,
- //както и дали тя се дели на 2, 3 или 5.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement