Check if the product of digit sum and its reverse equals the number or not Last Updated : 17 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Given a number, check whether the product of digit sum and reverse of digit sum equals the number or not.Examples: Input : 1729 Output : Yes Explanation: digit sum = 1 + 7 + 2 + 9 = 19 Reverse of digit sum = 91 Product = digit sum * Reverse of digit sum = 19 * 91 = 1729 Input : 2334 Output : No Flowchart: Approach : 1. Find the sum of digits of a given number. 2. Reverse the digit sum output. 3. Product of digit sum and reverse of digit sum. If the product equals to the original number then print "Yes" else print "No". C++ // CPP implementation to check if the // product of digit sum and its // reverse equals the number or not #include<bits/stdc++.h> using namespace std; // Function that returns number after // performing operations. int check(int num) { int digitSum = 0; // loop used to count digit sum // of numbers. while(num > 0) { digitSum = digitSum + num % 10; num = num / 10; } int temp = digitSum; int reverseDigitSum = 0; // loop that reverse digit sum. while(temp > 0) { int rem = temp % 10; reverseDigitSum = reverseDigitSum * 10 + rem; temp = temp / 10; } // product of digit sum and reverse digit // sum and assign it to number variables. int number = digitSum * reverseDigitSum; return number; } // Driver function int main() { int num = 1729; // call check() function. int x = check(num); // check if original number equals // to x or not if (num == x) cout << "Yes"; else cout << "No"; return 0; } Java // JAVA implementation to check if the // product of digit sum and its // reverse equals the number or not import java.io.*; public class GFG { // Function that returns number after // performing operations. static int check(int num) { int digitSum = 0; // loop used to count digit sum // of numbers. while(num > 0) { digitSum = digitSum + num % 10; num = num / 10; } int temp = digitSum; int reverseDigitSum = 0; // loop that reverse digit sum. while(temp > 0) { int rem = temp % 10; reverseDigitSum = reverseDigitSum * 10 + rem; temp = temp / 10; } // product of digit sum and reverse digit // sum and assign it to number variables. int number = digitSum * reverseDigitSum; return number; } // Driver function public static void main(String args[]) { int num = 1729; // call check() function. int x = check(num); // check if original number equals // to x or not if (num == x) System.out.println("Yes"); else System.out.println("No"); } } // This code is contributed by Nikita Tiwari Python3 # Python implementation to check if the # product of digit sum and its # reverse equals the number or not # Function that returns number after # performing operations. def check(num) : digitSum = 0 # loop used to count digit sum # of numbers. while(num != 0) : digitSum = digitSum + num % 10 num = num // 10 temp = (int)(digitSum) reverseDigitSum = 0 # loop that reverse digit sum. while(temp != 0) : rem = temp % 10 reverseDigitSum = reverseDigitSum * 10 + rem temp = temp // 10 # product of digit sum and reverse digit # sum and assign it to number variables. number = digitSum * reverseDigitSum return number # Driver function num = 1729 # call check() function. x = (check(num)) # check if original number # equals to x or not if (num == x) : print("Yes") else : print("No") # This code is contributed by Nikita Tiwari. C# // Code to check if the product // of digit sum and its reverse // equals the number or not using System; class GFG { // Function that returns number // after performing operations. static int check(int num) { int digitSum = 0; // loop used to count digit // sum of numbers. while (num > 0) { digitSum = digitSum + num % 10; num = num / 10; } int temp = digitSum; int reverseDigitSum = 0; // loop that reverse digit sum. while (temp > 0) { int rem = temp % 10; reverseDigitSum = reverseDigitSum * 10 + rem; temp = temp / 10; } // product of digit sum and // reverse digit sum, assign // it to number variables. int number = digitSum * reverseDigitSum; return number; } // Driver function public static void Main() { int num = 1729; // call check() function. int x = check(num); // check if original number // equals to x or not if (num == x) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } // This code is contributed by Anant Agarwal. PHP <?php // PHP implementation to check if the // product of digit sum and its // reverse equals the number or not // Function that returns number // after performing operations. function check($num) { $digitSum = 0; // loop used to count // digit sum of numbers. while($num > 0) { $digitSum = $digitSum + $num % 10; $num = (int)($num / 10); } $temp = $digitSum; $reverseDigitSum = 0; // loop that reverse // digit sum. while($temp > 0) { $rem = $temp % 10; $reverseDigitSum = $reverseDigitSum * 10 + $rem; $temp = (int)($temp / 10); } // product of digit sum // and reverse digit // sum and assign it // to number variables. $number = $digitSum * $reverseDigitSum; return $number; } // Driver Code $num = 1729; // call check() function. $x = check($num); // check if original // number equals // to x or not if ($num == $x) echo("Yes"); else echo("No"); // This code is contributed by Ajit. ?> JavaScript <script> // JavaScript implementation to check if the // product of digit sum and its // reverse equals the number or not // Function that returns number after // performing operations. function check(num) { var digitSum = 0; // loop used to count digit sum // of numbers. while (num > 0) { digitSum = digitSum + (num % 10); num = parseInt(num / 10); } var temp = digitSum; var reverseDigitSum = 0; // loop that reverse digit sum. while (temp > 0) { var rem = temp % 10; reverseDigitSum = reverseDigitSum * 10 + rem; temp = parseInt(temp / 10); } // product of digit sum and reverse digit // sum and assign it to number variables. var number = digitSum * reverseDigitSum; return number; } // Driver function var num = 1729; // call check() function. var x = check(num); // check if original number equals // to x or not if (num == x) document.write("Yes"); else document.write("No"); </script> OutputYes Time Complexity: O(log10(num))Auxiliary Space: 1 Comment More infoAdvertise with us Next Article Check if a number with even number of digits is palindrome or not D Dharmendra kumar Improve Article Tags : Misc DSA Basic Coding Problems number-digits Practice Tags : Misc Similar Reads Smallest number k such that the product of digits of k is equal to n Given a non-negative number n. The problem is to find the smallest number k such that the product of digits of k is equal to n. If no such number k can be formed then print "-1".Examples: Input : 100 Output : 455 Explanation: 4*5*5 = 100 and 455 is the smallest possible number. Input : 26 Output : - 10 min read Check if the Sum of Digits is Palindrome or not Given an integer n, the task is to check whether the sum of digits of n is palindrome or not.Example: Input: n = 56 Output: trueExplanation: Digit sum is (5 + 6) = 11, which is a palindrome.Input: n = 51241 Output: falseExplanation: Digit sum is (5 + 1 + 2 + 4 + 1) = 13, which is not a palindrome.Ta 9 min read Check if the sum of digits of a number divides it Given a number n, the task is to check if the sum of digits of the given number divides the number or not. Examples: Input : n = 12Output : YesExplanation: Sum of digits = 1+2 =3 and 3 divides 12.Input : n = 15Output : NoExplanation: Sum of digits = 1+5 =6 and 15 % 6 != 0.Using Iterative Method - O( 6 min read Check if the sum of digits of a number divides it Given a number n, the task is to check if the sum of digits of the given number divides the number or not. Examples: Input : n = 12Output : YesExplanation: Sum of digits = 1+2 =3 and 3 divides 12.Input : n = 15Output : NoExplanation: Sum of digits = 1+5 =6 and 15 % 6 != 0.Using Iterative Method - O( 6 min read Check if a number with even number of digits is palindrome or not Given a number N containing an even number of digits. The task is to check whether that number is palindrome or not. Examples: Input: N = 123321 Output: Palindrome Input: 1234 Output: Not palindrome A Naive Approach is to traverse from the front and back of that number and stop where they do not mat 4 min read Check if a number with even number of digits is palindrome or not Given a number N containing an even number of digits. The task is to check whether that number is palindrome or not. Examples: Input: N = 123321 Output: Palindrome Input: 1234 Output: Not palindrome A Naive Approach is to traverse from the front and back of that number and stop where they do not mat 4 min read Like