Data Mining-while: In the University Examinations conducted during the past 5 years, the toppers registration numbers were 7126, 82417914, 7687 and 6657. Your father is an expert in data mining and he could easily infer a pattern in the toppers registration numbers.
In all the registration numbers listed here, the sum of the odd digits is equal to the sum of the even digits in the number. He termed the numbers that satisfy this property as Probable Topper Numbers.
Write a program to find whether a given number is a probable topper number or not.
Input Format:
Input consists of a single integer.
Output Format:
Output consists of a single line. Refer sample output for details.
Sample Input 1:
143
Sample Output 1:
yes
Sample Input 2:
344
Sample Output 2:
no
Solution
#include <iostream>
using namespace std;
int main()
{
int n, n1, sum = 0, sum1 = 0;
scanf("%d", &n);
while (n > 0)
{
n1 = n % 10;
if (n1 % 2 == 0)
{
sum = sum + n1;
}
else
{
sum1 = sum1 + n1;
}
n = n / 10;
}
if (sum == sum1)
{
printf("yes");
}
else
printf("no");
return 0;
}
Happy Learning – If you require any further information, feel free to contact me.