Anonymous user
Integer comparison: Difference between revisions
no edit summary
(add C) |
No edit summary |
||
Line 1:
boacelcomo
{{task}}
{{basic data operation}}
Line 78 ⟶ 79:
int a, b;
scanf("%d %d", &a, &b);
2000
if (a < b)
Line 375 ⟶ 378:
Other comparison operators are "<=", ">=" and "!=".
Note that Tcl doesn't really have a notion of a variable "type" - all variables are just strings of bytes and notions like "integer" only ever enter at interpretation time. Thus the above code will
2000
ork correctly for "5" and "6", but "5" and "5.5" will also be compared correctly. It will not be an error to enter "hello" for one of the numbers ("hello" is greater than any integer). If this is a problem, the type can be expressly cast
if { [int $x] > [int $y] } { puts "$x is greater than $y" }
|