Join Regular Classroom : Visit ClassroomTech

Wipro NLTH Coding Solve | Online Game | Codewindow.in

You are playing an online game. In the game, a numbers is displayed on the screen. In order to win the game, you have to Count the trailing zeros in the factorial value of the given number. Write an algorithm to count the trailing zeros in the factorial value of the given number.

Input
The input consists of an integer num, representing the number displayed on the screen.

Output
Print An integer representing the count of trailing zeros in the factorial of the given numbers.
Note: The factorial of the number is calculated as the product of integer numbers from 1 to num.

Constraints
NA

Example

Input:
5

Output:
1

Explanation:
On calculating the factorial of 5, the output is 120 (1 x2x3x4x5). There is only one trailing 0 in 120, So the output is 1.

#include <stdio.h>
int main()
{
    int num;
    scanf("%d", &num);
    long int f=1;
    int tzero=0;
    for(int i=1;i<=num;i++)
        f=f*i;
    while(f)
    {
        if(f%10==0)
        {
            tzero++;
        }
        else
            break;
        f=f/10;
    }
    printf("%d", tzero); 
}

Solution: In JAVA

import java.util.Scanner;
class ZeroCount {
    public static int CountZero(int n){ 
        int s=0;
        int c= n / 5;  
        System.out.println(c);
        if(c>5){
            s=c/5; 
        }
        System.out.println(s);
        return s+c;
    } 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        System.out.println(CountZero(num));
    }
}

Also Checkout

Recent Posts
Categories
Pages