Home > Back-end >  The small white for help ~!
The small white for help ~!

Time:10-24

Small white is self-study C language to realize two digital input, output the maximum number of features, and make the following the procedure, but every time the output is the input of the first number, don't know what's wrong, so the teacher please help and see what is wrong?
# include
Int main ()
{
Int a, b, Max;
The scanf (" % d, % d ", & amp; A, & amp; B);
If (a> Max=a, b);
The else Max=b;
Printf (" Max=% d \ n ", Max).

}

CodePudding user response:

Input two Numbers with a comma in English try it?

CodePudding user response:

Because the building without memory will input b to b,
With attention to the building of the scanf, comma, when the input to keep the agreement and the scanf format, that is, the comma is Chinese, the input to input Chinese comma, comma or input English.

CodePudding user response:

General logic there is no problem, but generally need a return 0; The return value, because you are using is int as the main function return values,
Source:
 
# include
Int main ()
{
Int a, b, Max;
The scanf (" % d, % d ", & amp; A, & amp; B);
If (a> B)
Max=a;
The else
Max=b;
Printf (" Max=% d \ n ", Max).
return 0;
}


But pay attention to when the input is a, b, not a, b, is a comma between a and b, not Spaces,

CodePudding user response:

Fyi:
 # include & lt; Stdio. H> 
Int main ()
{
Int a, b, n, v, r, k;
Char buf [80].
Char * p;

K=0;
R=EOF.
While (1) {
If (EOF==r) {
The fgets (buf, 80, stdin);
P=buf.
}
While (1) {
R=sscanf (p, "% d % n, & amp; V, & amp; N);
If (1==r) {k++; break; }
If (EOF==r) break;
P++;
}
If (EOF==r) continue;
P +=n;
If (1==k) a=v;
If (2)==k {
B=v;
break;
}
}
Printf (" % d, % d \ n ", a, b);
return 0;
}
  • Related