Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
284 B
3
Indexable
Never
#include<stdio.h>

int sum_of_odd_digits(int n) {
	int r, sum = 0;
	while (n > 0) {
		r = n % 10;	
		n = n / 10;	
		if (r % 2 == 1)
			sum = sum + r;
	}
	return sum;
}

int main() {
	int n;
	printf("Enter a Number: ");
	scanf("%d", &n);
	printf("Odd Sum: %d", sum_of_odd_digits(n));
}