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. Now, write a program to find whether a given number is a probable topper number or not.
Answers
Answer:
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int reverse(int n)
{
int rev = 0;
while (n != 0) {
rev = (rev * 10) + (n % 10);
n /= 10;
}
return rev;
}
void getSum(int n)
{
n = reverse(n);
int sumOdd = 0, sumEven = 0, c = 1;
while (n != 0) {
if (c % 2 == 0)
sumEven += n % 10;
else
sumOdd += n % 10;
n /= 10;
c++;
}
if(sumOdd==sumEven)
cout<<"Yes";
else
cout<<"No";
}
int main()
{
int n ;
cin>>n;
getSum(n);
return 0;
}
Explanation:
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. Now, write a program to find whether a given number is a probable topper number or not.
Answer:
#include<iostream>
using namespace std;
int main()
{
//Type your code here.
int n,i,j,sum1,sum2,s3;
cin>>n;
int temp1=n;
int temp2=n;
for(i=1;i<=2;i++)
{
int rem1=temp1%10;
sum1=sum2+rem1;
temp1=temp1/10;
}
for(j=0;j<=2;j++)
{
int rem2=temp1%10;
sum2=sum2+rem2;
temp2=temp2/10;
}
if(sum1==sum2)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
}
Explanation:
all the cases passes except one hidden.can any one help please