#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long j,x;



long k=1;

long y=0;
cin>>x;
for(;k!=x+1;)
	      {

	       for(;k%5==0;)
		y++;
	       k++;
	      }

cout<<y;

getch();
}

in above code i am trying to find the total no of zeroes at the and of factorial of no..........in doing this i am finding out total no of 5 in the
factorial product of the no
suppose to find out the toal no of zeroes at the end in the factorial of 20
5*4,19,18,17,16,3*5,14,13,12,11,5*2,9,8,7,6,5,4,3,2,1
by taking each no from above in second for loop i am counting the total no 5 in complete list as in above the total no of 5 are 4 so the zeroes 4(at the end in the factorial of 20)

now the problem is that whenever i enter any no greater than or equal to 5 it does not output anything and got stuck there..where is the prob?

Recommended Answers

All 2 Replies

Here is your faulty code :

for(;k%5==0;)
                       y++;
k++;

Your k%5 checks if its value is 0 until its not zero k++ executes very well.Once k becomes a multiple of 5 then the for loop

for(;k%5==0;)
                       y++;

Will never quit because you will increase y , and k's value is not altered whatsoever.

thanks buddy now i have changed the code updated the value of k ..now its perfect

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.