Y
Y
Yuri2020-10-24 14:18:16
C++ / C#
Yuri, 2020-10-24 14:18:16

How to display the number Y?

Can you help with the program? Here is the condition: You are given a three-digit integer. All digits must be non-zero. Output a new three-digit number, each digit of which is the remainder of dividing the number 25 by the corresponding digit of the number. It is the number that should be displayed (it may have fewer digits if the first digits turn out to be zero), and not three digits are displayed sequentially. Here is my code:

#include <iostream>
#include <cmath>
 using namespace std;
 int main()
 {
     setlocale(LC_ALL, "RUS");
     int x, y;
     cout << "Введите трехзначное число\n";
     cin >> x;
     int a, b, c;
     a = x % 25;
     b = x % 25;
     c = x % 25;
     int sum = a + b + c;
     cout << "Введите однозначное число\n";
     cin >> y;
     (sum % y != 0) ? cout << y << " " :cout<<"NO\n"; 
       system("pause");
       return 0;    
 }

What is wrong here? Can you help please?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-10-24
@zagayevskiy

You divide by 25 not the digits of the number, but the number itself. Hint - the last (rightmost) digit of a number can be obtained by taking the remainder of the division by 10.
Further, you are going to get the number also incorrectly, simply summing up the results. You need to multiply by the appropriate order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question