#include
int main()
{
int size,i;
std::cin >> size;
int*fact;
fact = new int[size];
for (i = 0; i < size; i++)
{
std::cin >> fact[size];
}
for (i = 0; i < size; i++)
{
int con = 5;
int multiple = 0;
do
{
multiple = multiple+(fact[size] / con);
con = con * 5;
} while (con < fact[size]);
std::cout << multiple <<'\n';
}
return 0;
}
my code breaks for multiple i/p…it works when only one number is given…for multiple i/p it prints the answer for the last i/p again n again…need help…
In your do while loop replace fact[size] by fact[i] both in the body of the loop and condition statement. fact[size] will always be the last element.
1 Like
Take the input into fact[i] and not fact[size].
Also at the time of calculation, find trailing zeros for fact[i] not fact[size].
#include<iostream>
using namespace std;
int main() {
int size,i;
std::cin >> size;
int *fact;
fact = new int[size];
for (i = 0; i < size; i++)
{
std::cin >> fact[i];
}
for (i = 0; i < size; i++)
{
int con = 5;
int multiple = 0;
do
{
multiple = multiple+(fact[i] / con);
con = con * 5;
} while (con < fact[i]);
std::cout << multiple <<'\n';
}
return 0;
}
yeah don’t confuse with fact[i] and fact[size]
yes i corrected that too…thank you
1 Like