Tuesday, March 5, 2024

36. Sum of all odd position and even position digits :—

 36. Sum of all odd position and even position digits :—


#include<stdio.h>

int main()

{

    int i,sumo,sume,n,r;

    i=0,sumo=0,sume=0;

    printf("enter a value of n ");

    scanf("%d",&n);

    while(n>0)

    {

        r=n%10;

        if(i%2==0)

        {

            sume=sume+r;

            printf("sum of even positions=%d\n",sume);

        }

        else

        {

            sumo=sumo+r;

            printf("sum of odd positions=%d\n",sumo);

        }

        n=n/10;

        i++;

    }

    return 0;

}


No comments:

Post a Comment