Problem Name :
Counting trailing zeros
Problem link :
My java code :
import java.math.BigInteger;
import java.util.Scanner;
public class RemainingZeros {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger N = scanner.nextBigInteger();
double Array[] = new double[N.intValue()];
for (int i = 0; i < N.intValue(); i++) {
Array[i] = scanner.nextDouble();
}
for (int i = 0; i < N.intValue(); i++) {
int count = 0;
for (double j = 0; j <= Array[i]; j += 5) {
double temp = j;
while (temp % 5 == 0 && temp > 0) {
count++;
temp = temp / 5;
}
}
System.out.println(count);
}
scanner.close();
}
}
My C Code:
#include <stdio.h>
int main(){
int N;
scanf("%d",&N);
int Array[N];
for(int i=0;i<N;i++){
scanf("%d",&Array[i]);
}
for (int i = 0; i < N; i++) {
int count = 0;
for (int j = 0; j <= Array[i]; j += 5) {
int temp = j;
while (temp % 5 == 0 && temp > 0) {
count++;
temp = temp / 5;
}
}
printf("%d",count);
printf("\n");
}
}
Can anyone tell me solution for this, “Time limit exceed” Problem??