Given the maximum of 100 digits number as input,find the difference between sum of oddd and even postion digits in c
Answers
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