Home > Back-end >  Any input from the keyboard, two symbols of different integers until input two integers to meet requ
Any input from the keyboard, two symbols of different integers until input two integers to meet requ

Time:09-18

#include
Int main ()
{int x1, x2,
Do
{fflush (stdin);
Printf (" Input x1, x2: \ n ");
The scanf (" % d, % d ", & amp; X1, & amp; X2);
X2} while (x1 * & gt;=0);
Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}
Manual debugging clearly no problem, why in the test site says running time is beyond limit?

CodePudding user response:

While (x1 * x2 & gt;=0); To the while (x1 * x2 & gt; 0); Try

CodePudding user response:

Seems to optimize the program, feel the printf aren't going to be output every time, do not brush the buffer can also
 
#include
Int main ()
{
Int x1, x2,
Printf (" Input x1, x2: \ n ");
Do
{
The scanf (" % d, % d ", & amp; X1, & amp; X2);
X2} while (x1 * & gt;=0);
Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}

CodePudding user response:

Forget to send in the past, the topic,,
Any input from the keyboard, two symbols of different integers until input two integers meet the requirements, then print the two Numbers, please to pass the test to find out the problems existing in the application (more than one problem oh), and correct, and at the same time with the following the running result of the example is given to check the modified program,
#include
Int main ()
{
Int x1, x2,
Do {
Printf (" Input x1, x2, ");
The scanf (" % d, % d ", & amp; X1, & amp; X2);
X2} while (x1 * & gt; 0);
Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}

Program correct operation example results:
Input the x1, x2:
A, s ↙
Input the x1, x2:
A, 1 ↙
Input the x1, x2:
2 s ↙
Input the x1, x2:
1, 2 ↙
Input the x1, x2:
1, - 2 ↙
Input the x1, x2:
0, 3 ↙
Input the x1, x2:
1.2, 3.4 ↙
Input the x1, x2:
1.2, 5 ↙
Input the x1, x2:
- 1, 3 ↙
X1=1, x2=3


Input format:
"% d, % d"

The output format:
Input message: "Input x1, x2: \ n", "
Output: "x1=% d, x2=% d \ n", "

Input the sample:


The output sample:

Time limit: 500 ms memory limit: 32000 KB

CodePudding user response:

/* * & lt;
Subject content:
Any input from the keyboard, two symbols of different integers until input two integers meet the requirements of
Then print this two Numbers, please to pass the test to find out the problems existing in the application (more than one problem oh),
And correct, and at the same time with the following the running result of the example is given to check the modified program,
#include
Int main ()
{
Int x1, x2,
Do {
Printf (" Input x1, x2, ");
The scanf (" % d, % d ", & amp; X1, & amp; X2);
X2} while (x1 * & gt; 0);
Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}

Program correct operation example results:
Input the x1, x2:
A, s ↙
Input the x1, x2:
A, 1 ↙
Input the x1, x2:
2 s ↙
Input the x1, x2:
1, 2 ↙
Input the x1, x2:
1, - 2 ↙
Input the x1, x2:
0, 3 ↙
Input the x1, x2:
1.2, 3.4 ↙
Input the x1, x2:
1.2, 5 ↙
Input the x1, x2:
- 1, 3 ↙
X1=1, x2=3


Input format: "% d, % d"
The output format:
Input message: "Input x1, x2: \ n", "
Output: "x1=% d, x2=% d \ n", "
*/
#include
#include
#include

Int main ()
{
Int x1, x2, n, flag;


Do
{
Flag=0;
Printf (" Input x1, x2: \ n ");

N=the scanf (" % d, % d ", & amp; X1, & amp; X2);

The switch (n)
{
Case 0:
While (getchar ()!='\ n');

Flag=1;
break;
Case 1:
While (getchar ()!='\ n');
Flag=1;
break;
Default:
If (x1 * x2 & gt;=0)
Flag=1;
The else
Flag=0;

break;

}

}
While (flag==1);

Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}

CodePudding user response:

#include
Int main ()
{
Int x1, x2, n.
Printf (" Input x1, x2: \ n ");
N=the scanf (" % d, % d ", & amp; X1, & amp; X2);
While (n! * x2=2 | | x1 & gt;=0)
{
fflush(stdin);
Printf (" Input x1, x2: \ n ");
N=the scanf (" % d, % d ", & amp; X1, & amp; X2);
}
Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}

CodePudding user response:

 # include & lt; stdio.h> 

Int main ()
{
Int x1, x2, check;
Printf (" Input x1, x2: \ n ");
Check=the scanf (" % d, % d ", & amp; X1, & amp; X2);
While ((check!=2) | | (x1 * x2 & gt;=0))
{
While (getchar ()!='\ n');
Printf (" Input x1, x2: \ n ");
Check=the scanf (" % d, % d ", & amp; X1, & amp; X2);
}
Printf (" x1=% d, x2=% d \ n ", x1, x2);
return 0;
}
  • Related