Question

In: Computer Science

what is the best code to construct a C++ program that finds a five digit number;...

what is the best code to construct a C++ program that finds a five digit number; This number should reverses the order of its digits when multiplied by four. Also, how many five digits numbers are there in which the sum of the digits is even.

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
using namespace std;

bool isOk(int num)
{
string n = to_string(num);
string rev = to_string(num*4);
reverse(rev.begin(), rev.end());
return rev.compare(n)==0;
  
}
int main() {
   // declare variables
   int start = 10000;
   int end = 99999;
  
   // loop from start to end
   int count = 0;
   for(int i=start;i<=end;i++)
   {
   if(isOk(i))
   { cout<<i<<endl;
   count++;
   }
   }
   cout<<"There are only "<<count<<" such numbers.";
   return 0;
}

=============================

SCREENSHOT:


Related Solutions

Java Code!!!! A five-digit number is said to be friendly if: the leftmost digit is divisible...
Java Code!!!! A five-digit number is said to be friendly if: the leftmost digit is divisible by 1 and the leftmost two digits are divisible by 2 and the leftmost 3 digits are divisible by 3 and the leftmost 4 digits are divisible by 4 and leftmost 5 digits (the five-digit number itself) is divisible by 5. For example, the number 42325 is a friendly number: 4 is divisible by 1 and 42 is divisible by 2 and 423 is...
4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data,...
4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data, determines whether all the digits of the number are even. For example, if the number were 5688, it would not meet the condition since the most significant digit (5) is odd; if on the contrary, the number were 6244, it would be true, since all the digits are even. 5. Make the flowchart and the C ++ program that, when receiving N integers as...
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
Write a program in C that takes as input a four-digit hexadecimal number and prints the...
Write a program in C that takes as input a four-digit hexadecimal number and prints the next 10 hexadecimal numbers. Define a hexadecimal number as int hexNum[4] Allow upper- or lowercase letters for input and use uppercase letters for the hexadecimal output. For example, 3C6f should be valid input and should produce output 3C6F, 3C70, 3C71, . . . .
Code the FSM in C++, and show that the program works. Construct a Finite State Machine...
Code the FSM in C++, and show that the program works. Construct a Finite State Machine that models an old-fashioned soda machine that accepts nickels, dimes, and quarters. The soda machine accepts change until 35 cents have been put in. It gives change back for any amount greater than 35 cents. Then the customer can push buttons to receive either a cola, a root beer, or a ginger ale.
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold by three vendors in four different zones. Is required:  Request the sale amount of each seller by zone, the values must be entered through the keyboard and validate that it does not accept negative numbers.  Menu that requests the operation to be carried out. In case of entering an invalid data, send an error message and request the operation again.  Option...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained by 3 amounts in five different zones. Is required: + Request the total of votes by zone of each candidate, the values must be entered on the keyboard and validate that it does not accept negative numbers + Menu that requests the operation to be performed, in case of entering an invalid data send an error message and request the operation again + Option...
Program 5: The concept of a 5-digit palindromenumber is a 5-digit number that reads the...
Program 5: The concept of a 5-digit palindrome number is a 5-digit number that reads the same from left to right and from right to left. For example, 12121, 45454, and 14741 are valid 5-digit palindrome numbers. Design (pseudocode) and implement (source code) a program (name it FiveDigitPalindrom) that reads a 5-digit number from the user (as integer value, not string) and then mathematically (using division and remainder operations) determines whether the entered number is a 5-digit palindrome or not....
Write a java program The last digit of a credit card number is the check digit,...
Write a java program The last digit of a credit card number is the check digit, which protects againts transaction errors. The following method is used to veryfy credit card numbers. For the simplicity we can assume that the credit card has 8 digits instead of 16. Follwing steps explains the algorithm in determining if a credit card number is a valid card.  Starting from the right most digit, form the sum of every other digit. For example, if...
There are at least five (probably more) places in the attached C# program code that could...
There are at least five (probably more) places in the attached C# program code that could be optimized. Find at least five things in the Program.cs file that can be changed to make the program as efficient as possible. List five problems you found with the code (Put your list either in comments within the code or in a separate Word or text document), and then optimize the code in the attached code below to make it as efficient as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT