Write a Java program to compute the number of trailing zeros in a factorial.

 /* Write a Java program to compute the number of trailing zeros in a

factorial.

7! = 5040, therefore the output should be 1 */

import java.util.*;

class Ten

{

public static void main(String arg[])

{

Scanner obj = new Scanner(System.in);


int no , a=1 , b , c=0 , d=0;

int arr[] = new int[20];


System.out.print("\nEnter number to find factorial \n and it's trailing zeros: ");

no = obj.nextInt();


if(no != 0)

{

for(int i=no ; i>0 ; i--)

{

a = a * i;

}

System.out.println("\nFactoriyal is : " + a );

} 

else

{

System.out.println("Enterd number is zero");

}

while(a != 0)

{

b = a % 10;

arr[c] = b;

c++;

a = a / 10;


}

for (int i=0 ; i<c ; i++) 

{

if(arr[i]==0)

{

d++;

}

else

{

break;

}

}

System.out.println("number of trailing zeros is: " + d);

}

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel



Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.