1 / 12
Jan 2016

For problem FCTRl used the following code and I get wrong answer on ideone. However I get the expected output in my compiler.
int no_of_zeroes(int n){
int v=0;
int i=1;
do{
v+= n/(pow(5,i));
i++;
}while(pow(5,i) return v;
}
int main(){
int t;
cin>>t;
for (int i=0;i int n; cin>>n;
cout<}
return 0;
}

  • created

    Jan '16
  • last reply

    Jan '16
  • 11

    replies

  • 1.2k

    views

  • 2

    users

  • 1

    like

  • 1

    link

please use code tags or preformatted text to show your code in readable form. The problem code is not correct.

And the code is not complete - I would test it if it worked. As I am not an expert in C++, for me it is not obvious what is missing.

? I dont know what this number may be?
If you need help you should post a complete and runable code. I was not able to run your code at e.g. ideone.com

include

include

using namespace std;

int main(){
int t;
cin>>t;

int n[t];

for (int i=0;i{
cin>>n[i];
}

for (int i=0;i int v=0;
int j=1;
do{
v+= n[i]/(pow(5,j));
j++;
}while(pow(5,j) cout<

}

return 0;
}

include < iostream>

include< math.h>

using namespace std;

int main(){
int t;
cin>>t;

int n[t];

for (int i=0;i{
cin>>n[i];
}

for (int i=0;i int v=0;
int j=1;
do{
v+= n[i]/(pow(5,j));
j++;
}while(pow(5,j) cout<

}

return 0;
}

Edit your post. Paste your code. Highlight it all and click on the "preformatted text" button.
Or put your code within [code]...[/code]
a code line like
for (int i=0;i{
still doesn't compile

#include<iostream>
#include<math.h>
 using namespace std;

int main()

{
int t;
cin>>t;
int n[t];
for (int i=0;i {
cin>>n[i];
}

 for (int i=0;i<t;i++){
    int v=0;
    int j=1;
    do{
        v+= n[i]/(pow(5,j));
        j++;
      }while(pow(5,j)<n[i]);
      cout<<v<<endl;

}


return 0;
}

Assuming that your code is meant to be this:

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    int n[t];

    for (int i=0; i<t; i++)
    {
        cin>>n[i];
    }

    for (int i=0; i<t; i++)
    {
        int v=0;
        int j=1;
        do
        {
            v+= n[i]/(pow(5,j));
            j++;
        }
        while(pow(5,j)<n[i]);
        cout<<v<<endl;

    }


    return 0;
}

try this case:
4
24
25
29
30

I am getting the answer as
4
5
6
7

but I guess the correct answer is
4
5
6
7

but I dont understand what is causing this error

I am no expert in C++. Anyway, I would think about integer arithmetic. The pow function returns float, doesn't it?

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 7d

Want to read more? Browse other topics in C and C++ or view latest topics.