Sum Of Odd Digits

Given an number the task is to find the sum of odd digits present in the number.

Example 1: Let us take a numberĀ 83213. Here the sum of odd digits is 3+1+3 = 7.

C
#include <stdio.h>
int main()
{
    int n=0,r=0,sum=0;
    printf("Enter a number: ");
    scanf("%d",&n);
    while(n>0)
    {
        r=n%10;
        if(r%2!=0)
        {
            sum=sum+r;
        }
        n=n/10;
    }
    printf("Sum of odd digits: %d",sum);
}
C