Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class trailingZeros{
- public static void main(String a[]){
- Scanner sc = new Scanner(System.in);
- boolean cont = true;
- while(cont){
- System.out.print("Enter the Number : ");
- int number = sc.nextInt();
- countZeros(number);
- System.out.print("\nDo you want to continue (1/0) : ");
- int n = sc.nextInt();
- if(n==0){
- cont = false;
- }
- }
- }
- static void countZeros(int number){
- int div = 5,quotient;
- int zeros = 0;
- while(number >= div){
- quotient = number/div;
- div *= 5;
- zeros += quotient;
- }
- System.out.println("The Trailing number of zeros in the factorial of " + number + " are : " + zeros);
- return;
- }
- }
Add Comment
Please, Sign In to add comment