Advertisement
BojidarDosev

zadacha

Mar 16th, 2024
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cmath>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int num, num2 = 0, sum = 0;
  12.     vector <int> nums = {};
  13.     cout << "Enter a number between 100 and 999: ";
  14.     cin >> num;
  15.     cout << endl;
  16.  
  17.     if (num < 100 || num > 999)
  18.     {
  19.         cerr << "Invalid input, try again!" << endl;
  20.         return 1;
  21.     }
  22.  
  23.     cout << "Reversed number: " << endl;
  24.  
  25.     while (num>0)
  26.     {
  27.         num2 = num % 10;
  28.         num = num / 10;
  29.         sum += num2;
  30.         nums.push_back(num2);
  31.         cout << num2;
  32.     }
  33.  
  34.     cout << endl;
  35.     cout << "Stotici desetici edenici: " << endl;
  36.     reverse(nums.begin(), nums.end());
  37.  
  38.     for ( int i = 0; i < 3; i++)
  39.     {
  40.         cout << nums[i] << " ";
  41.     }
  42.    
  43.     cout << endl<< "Sumata na cifrite na chisloto e: "<< sum << endl;
  44.    
  45.     if (sum % 2 == 0) cout << "Deli se na 2!" << endl;
  46.     if (sum % 3 == 0) cout << "Deli se na 3!" << endl;
  47.     if (sum % 5 == 0) cout << "Deli se na 5!" << endl;
  48.     cout << "Ne se deli na 2,3 i 5!";
  49.    
  50.    
  51. }
  52.  
  53. //Да се напише програма, която подканва потребителя да въведе число в интервала [100,999], след което да се изведат
  54. //на отделни редове единиците, десетиците и стотиците на въведеното число. Да се изведе сумата на цифрите на числото,
  55. //както и дали тя се дели на 2, 3 или 5.
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement