Home > Back-end >  For help
For help

Time:01-19

While (the scanf (" % d ", & amp; A)==1) why I can't input end after the enter key? (a type is an int)
Submitted to the oj platform and the results
The compiler input characters to display the results

CodePudding user response:

A carriage return is the content of the input buffer to brush into memory, if there is no content in the input buffer, so how to brush to memory?

CodePudding user response:

#include
#include
using namespace std;
Long long a, s, I, w;
Int main () {
While (the scanf (" % d ", & amp; A)==1) {
S +=a;
i++;
}
W=1;
for(int j=1; JW *=2;
cout
return 0;
}

CodePudding user response:

The
reference 1/f, confident boy reply:
a carriage return is the brush to the memory of the content of the input buffer, if there is no content in the input buffer, then how to brush to memory?
program in the following, I input is 2 and enter but no output

CodePudding user response:

Behind the code % d space, when you enter 2 and enter the middle also should add Spaces,

CodePudding user response:

Reference: https://blog.csdn.net/21aspnet/article/details/174326
Suggestions to the following format:
 while (the scanf (" % d ", & amp; A), a) {//input end of 0 

CodePudding user response:

Write to you have any question, you should not have output, you have been input number then press enter, the program would have been the while (the scanf (" % d ", & amp; A)==1) in the loop, unless you enter illegal characters will end loop,

CodePudding user response:

reference 5 floor forever74 reply:
% d behind the space in the code, you enter 2 and enter the middle also should add Spaces,
with space it doesn't matter, formatted input will automatically ignore Spaces, only the space character transformation in strict accordance with the instructions string matching,
  • Related