Write a c program for a given a maximum 100 digit number as input ,find the difference between the sumof odd and even position digits
Answers
Answered by
0
Answer:
Write a c program for a given a maximum 100 digit number as input ,find the difference between the sumof odd and even position digits
Explanation:
Answered by
0
A c program for a given a maximum 100 digit number as input:
void getSum(int n)
{
// n = reverse(n);
int rev = 0;
while (n != 0)
{
rev = (rev * 10) + (n % 10);
n /= 10;
}
n = rev;
int sumofOdd = 0, sumofEven = 0, c = 1;
while (n != 0) {
if (c % 2 == 0)
sumofEven += n % 10;
else
sumofOdd += n % 10;
n /= 10;
c++;
}
cout << "Sum odd numbers = " << sumOdd << "\n";
cout << "Sum even numbers = " << sumEven;
}
Similar questions