Reputation: 45
I'm writing this program to find double digit odd numbers in a single number and I'm stuck.
For ex- In the number 56789 there are two double digit odd numbers: 67 & 89. I've written the code for this:
#include<stdio.h>
#include<conio.h>
int main()
{
int num,rem=0;
int odd=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num>0)
{
rem=(num%100);
printf("%d\n",rem);
if(rem%2!=0)
{
odd++;
}
num=num/10;
}
printf("Odd digits count is: %d",odd);
return 0;
}
Here's my problem:
Expected Output: 67 89 Total number of odd digit numbers: 2
Upvotes: 2
Views: 690
Reputation: 16726
while(num>0)
allows single and double digit numbers.
while(num>=10)
allows only double digit numbers.
Upvotes: 2