How to write a program to calculate the sum of digits present on even and odd places?

CODE




How to write a program to calculate the sum of digits present on even and odd places?

int main()
{
    int n,r,count=1,es=0,os=0;
    printf("\n enter the number:");
    scanf("%d",&n);
    while(n!=0)
    {
        r=n%10;
        if(count%2==0)
            es=es+r;
        else
            os+=r;
        n=n/10;
        count++;
    }
    printf("\n sum of even=%d",es);
    printf("\n sum of odds=%d",os);
}

Output:
enter the number: 34567

 sum of even=10
 sum of odds=15

How to write a program to calculate the sum of digits present on even and odd places? How to write a program to calculate the sum of digits present on even and odd places? Reviewed by Unknown on December 16, 2018 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.