Computer Science, asked by navalkishorebhardwaj, 7 months ago

Write a program in order to read a number and find product of even positioned digits and sum of odd positioned digits eg if number is 3465 then answer should be 3+4 =7 and 4*5=20​

Answers

Answered by keyboardavro
0

Answer:

for c

// C++ implementation of the approach  

#include <bits/stdc++.h>  

using namespace std;  

 

// Function that returns true if the product  

// of even positioned digits is equal to  

// the product of odd positioned digits in n  

bool productEqual(int n)  

{  

 

   // If n is a single digit number  

   if (n < 10)  

       return false;  

   int prodOdd = 1, prodEven = 1;  

 

   while (n > 0) {  

 

       // Take two consecutive digits  

       // at a time  

       // First digit  

       int digit = n % 10;  

       prodOdd *= digit;  

       n /= 10;  

 

       // If n becomes 0 then  

       // there's no more digit  

       if (n == 0)  

           break;  

 

       // Second digit  

       digit = n % 10;  

       prodEven *= digit;  

       n /= 10;  

   }  

 

   // If the products are equal  

   if (prodEven == prodOdd)  

       return true;  

 

   // If products are not equal  

   return false;  

}  

 

// Driver code  

int main()  

{  

   int n = 4324;  

 

   if (productEqual(n))  

       cout << "Yes";  

   else

       cout << "No";  

 

   return 0;  

}

Explanation:

Similar questions