C++ Program to find the number of trailing zeros in the factorial of a number [DEVCPP/GCC]


We intend to find the number of trailing zeros in the factorial of a number.
For example 1. If entered number (num) is 5, the factorial of 5 is :120, then
                         Output:1 (as there is only one zero at end in 120)
      example 2. If entered number (num) is 10 ,the factorial of 10 is:3628800
                         Output:2


//Program to find the number of trailing zeros in the factorial of a number

#include <iostream>

using namespace std;

int main()
{

      int count=0,num;                  //count initialized by 0

      cout<<"ENTER THE NUMBER:\n";
      cin>>num;
      cout<<"\nFINDING THE NUMBER OF TRAILING ZEROS IN THE FACTORIAL OF THIS NUMBER...\n\n";
 
for(int i=5 ; (num/i)>=1 ; i*=5)
{
          count + = num/i;   //loop counts the number of trailing zeros
}


cout<<"THE NUMBER OF TRAILING ZEROS IN THE FACTORIAL OF "<<num<<" IS:"<<count<<"\n";

}


Share this

Related Posts

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer

FIND US ON FACEBOOK!