by CodeChum Admin
Help, I'm lost!
I usually find my way around here but I somehow lost my glasses along the way. I can easily get back home as long as I can tell how many zeroes I left in my trail. Would you mind telling me how many zeroes are trailing?
Note: Trailing zeroes are the zeroes found at the right side of a number.
Input
1. The number to be evaluated
Constraints
This can only be a positive integer.
Output
The first line will contain a message prompt to input the number to be evaluated.
The second line will contain the number of trailing zeroes.
#include<stdio.h>
 
int main()
{
      int num, temp, count = 0;
      printf("\nEnter a Number:\t");
      scanf("%d", &num);
      temp = num;
      while(num >= 0)
      {
            if(num%10 == 0)
            {
                  count++;
                  num = num / 10;
            }
            else
            { 
                  break;
            }
      }       
      printf("\nNumber of Trailing Zeros in %d = %d\n", temp, count);
      return 0;
}
Enter a number: 2000
Number of Trailing Zeros in 2000 = 3
Comments