Home > Back-end >  The great god, help me, look at this problem
The great god, help me, look at this problem

Time:09-16

I waste solution:

Title:

Why don't you can do it? Dear bosses, help!!!! Thank you

CodePudding user response:

The parameters of the printf wrong
Change
Printf (" %. 6 lf ", sum);//note that sum outside the quotation marks

CodePudding user response:

No, I tried, there is wrong?
#include
using namespace std;
Int main () {
int n; Cin> n; Double sum=0;
for(int i=1; i<=n; I++) sum +=1.0/I;
Printf (" %. 6 lf ", sum);
return 0;
}
Twice, and then have a look

CodePudding user response:

And what's wrong???

CodePudding user response:

I also want to know
Is no good!

CodePudding user response:

Passing a doubt yourself to find a way to write a tracking display, to eliminate problems,

CodePudding user response:

reference 5 floor Liu Baolian reply:
I also want to know
Is there's no way


For a single positive integer, the program has no problem
But this brush problem sites, certainly not only tests a number, he will have a lot of test cases
So you have to cycle read input, otherwise only tested a program ended, the back of the test, is wrong

CodePudding user response:

 # include & lt; Iostream> 
using namespace std;

Int main ()
{
Cout. Flags (ios: : fixed);
Cout. Precision (6);//set output accuracy
int n;
While (cin> N)
{
Double sum=0;
For (int I=1; i <=n; I++)
The sum +=1.0/I;
Cout & lt; & lt; The sum & lt; & lt; Endl;
}
return 0;
}


In addition, you this is a C + + program, the output is what C is a bit strange

CodePudding user response:

I don't know, the teacher told us to ask the blog
  • Related