Home > Back-end >  New solution
New solution

Time:09-30

Topic: a positive number in multiples of 3 and 5, June 3 difference is multiple, please output meets the requirements of the smallest number of 15 and the number of output 15 five line
#include
Int main ()
{
Int I, num=0, sum=0;
For (I=0;; I++)
{
If ((I + 3) % 5==0 & amp; & (I - 3) % 6==0)
{
Sum=sum + I;
Num=num + 1;
}
If (num==15) break;
}
Printf (" % d \ n ", sum);
Num=0;
For (I=0;; I++)
{
If ((I + 3) % 5==0 & amp; & (I - 3) % 6==0)
{
Num=num + 1;
Printf (" % d 6 ", I);
}
If (num % 5==0)
printf("\n");
If (num==15) break;
}
return 0;
}
Why the code to run when a line of a page?

CodePudding user response:

Bro, because in front of the starting from 0 several number does not meet the if ((I + 3) % 5==0 & amp; & (I - 3) % 6==0) this condition, the num you has always been to 0, 0%5==0, so has been output line, the solution for the if (num % 5==0) printf (" \ n "); In a
If ((I + 3) % 5==0 & amp; & (I - 3) % 6==0)
{
Num=num + 1;
Printf (" % d 6 ", I);
}
This can solve inside, there is this code you can put inside a loop can be solved, don't need to make two for loop,

CodePudding user response:

 # include & lt; Iostream> 
using namespace std;
Int main () {
Int I=1;
Int num=0;
White (1) {
If (I % 3==0 & amp; I % 5==0 & amp; (1-3) % 6==0) {
Coutnum++;
}
If (num==15) return 0;
If (num % 5==0) {
Cout}
i++;
}
}

CodePudding user response:

refer to 2nd floor N - N - N response:
 # include & lt; Iostream> 
using namespace std;
Int main () {
Int I=1;
Int num=0;
White (1) {
If (I % 3==0 & amp; I % 5==0 & amp; (1-3) % 6==0) {
Coutnum++;
}
If (num==15) return 0;
If (num % 5==0) {
Cout}
i++;
}
}

Wrong is the while

CodePudding user response:

 
#include

Int main ()
{
Int I, num=0, sum=0;
For (I=1;; I++)
{
If ((I + 3) % 5==0 & amp; & (I - 3) % 6==0)
{
The sum +=I;
num +=1;
Printf (" % 5 d ", I);
If (num % 5==0)
printf("\n");
}

If (num==15)
break;
}
Printf (" % d \ n ", sum);
return 0;
}
  • Related