Trailing zeroes in factorial
PROBLEM :
For an integer n find number of trailing zeroes in n! .
Input:
The first line contains an integer 'T' denoting the total number of test cases. In each test cases, it contains an integer 'N'.
Output:
In each seperate line output the answer to the problem.
Constraints:
1<=T<=100
1<=N<=1000
Example:
Input:
1
9
Output:
1
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int Trailing_zeroes(int ) ;
int main()
{
int t,no ;
cin>>t ;
while(t--)
{
cin>>no ;
cout<<Trailing_zeroes(no)<<endl ;
}
return 0;
}
int Trailing_zeroes(int no)
{
int i , count ;
count=0 ;
for(i=5;no/i>=1;i*=5)
{
count+=no/i ;
}
return count ;
}
---------------------------------------------------------------------------------
For an integer n find number of trailing zeroes in n! .
Input:
The first line contains an integer 'T' denoting the total number of test cases. In each test cases, it contains an integer 'N'.
Output:
In each seperate line output the answer to the problem.
Constraints:
1<=T<=100
1<=N<=1000
Example:
Input:
1
9
Output:
1
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int Trailing_zeroes(int ) ;
int main()
{
int t,no ;
cin>>t ;
while(t--)
{
cin>>no ;
cout<<Trailing_zeroes(no)<<endl ;
}
return 0;
}
int Trailing_zeroes(int no)
{
int i , count ;
count=0 ;
for(i=5;no/i>=1;i*=5)
{
count+=no/i ;
}
return count ;
}
---------------------------------------------------------------------------------
Comments
Post a Comment