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...
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...
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.
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....
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...
Write JAVA program that finds 3 students with the best scores. The program asks users for...
Write JAVA program that finds 3 students with the best scores. The program asks users for scores of 5 students. The program prints the first, second, third place students and scores. You can assume that there is no two students with the same score. <EXAMPLE> enter the score of each student score of student 1: 50 score of student 2: 70 score of student 3: 30 score of student 4: 90 score of student 5: 40 1st place is student...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT