R Program to find the sum of odd digits of a number
In this program, You will learn how to find the sum of odd digits of a number in R.
Sum of odd digits are: 1234 => 1 + 3 = 4
Example: How to find the sum of odd digits of a number in R
{
n = as.integer(readline(prompt = "Enter a number :"))
s = 0
while (n > 0) {
r = n %% 10
if (r %% 2 != 0) {
s = s + r
}
n = n %/% 10
}
print(paste("Sum of the odd digits :", s))
}
Output:
Enter a number :1234
[1] "Sum of the odd digits : 4"