When I try to run this piece of code-
#include<iostream>
#include<stdio.h>
using namespace std;
long long fact(long long k)
{ return k/5 + k/25;
}
int main()
{
long long n,k;
scanf("%lld %lld", &n,&k);
while(n--)
{
scanf("%lld",&k);
printf("%d\n",fact(k));
}
}
with stdinput-
4
1
8
26
52
the output I get is-
1
6
12
12
instead of 0 1 6 12 .
Can someone explain this unexpected result ?
Your code is broken in two places:
Note that if you had compiled with warnings enabled (e.g.
gcc -Wall ...
) then your compiler would have pointed out the second mistake.LIVE DEMO