Tuesday, March 5, 2024

35. Sum of all odd digits :—

35. Sum of all odd digits :—


#include<stdio.h>

int main()

{

    int sum,n,r;

    sum=0;

    printf("enter a value of n ");

    scanf("%d",&n);

    while(n>0)

    {

        r=n%10;

        if(r%2!=0)

        {

            sum=sum+r;

        }

        n=n/10;

    }

    printf("%d",sum);

    return 0;

}


No comments:

Post a Comment