#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();

int k=0;

int x;
cout<<"input the no whose no of zeroes is to be calulated at the end in its factorial";
cin>>x;
for(int i=1;i<=x;i++)
{

while(i%5==0)
{
k++;
}
}
cout<<k;
getch();
}

hey in the above code it does not give compilation error but after i input the value of x after that it did nothing ,it just got stuck there and i have to break out of it ...means first cout get printed then i enter input x after that it dont show the value of k...in above program i am calculating the no of zeros at the end of factorial by calculating the total no of 5 in the factorial product..for example in factorial 10 there are two zeros because there are two 5 like this 5*2,9,8,7,6,5,4,3,2,1......tell me what i am doing wrong

ur code is getting hanged in the nested loop. correct that

hey how it is gettinghanged my loop is finite one...what to do then..and why it is getting hanged

#include <iostream>

using namespace std;

int main()
{
int i=0;
int s=1;
int N;
int factorial=1;
int sum=1;

cout << "Please Enter a number";
cin >> N;

while(N>2)
{
factorial = N * (N-1);
sum*=factorial;
N-=2;

}

cout<<sum<<endl;


return 0;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.