Advertisement
parad0xxxxx

[a,b] priekšpēdējais cipars ir 2

Jan 24th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a, b, sum, squared, i, footnote;
  8.  
  9. cout << "Enter the first value: ";
  10. cin >> a;
  11. cout << "Enter the second value: ";
  12. cin >> b;
  13. cout << endl;
  14.  
  15. if (a < b) {
  16. cout << "The sacred string is: ";
  17. }
  18. else if (a == b) {
  19. cout << "The second value can be equal to the first one, but the result will be only if the value's square penultimate number will be 2." << endl << "The sacred string is: ";
  20. }
  21. else {
  22. cout << "Something wrong. The second value must be larger than or equal to the first one.\n\n";
  23. return 0;
  24. }
  25.  
  26. sum = 0;
  27. squared = 0;
  28.  
  29. for (a; a <= b; a++)
  30. {
  31. squared = pow(a, 2);
  32.  
  33. for (i = 0; i < 2; i++)
  34. {
  35. if (squared % 10 == 2) {
  36. if (sum != 0) {
  37. cout << " + ";
  38. }
  39.  
  40. sum = sum + a;
  41. cout << a;
  42.  
  43. }
  44.  
  45. squared = squared / 10;
  46.  
  47. }
  48.  
  49. }
  50.  
  51. cout << " = " << sum << endl << endl;
  52.  
  53. return 0;
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement