C Examples Int Data Compare
# C Example - Number Comparison
[ C Examples](#)
### Comparing Two Numbers
The following example defines two integer variables and uses `if` to compare the two numbers. You can first look at the logic diagram:
!(#)
## Example
#includeint main(){int a, b; a = 11; b = 99; // You can also use the following code to let the user input two numbers in the terminal// printf("Enter the first value:");// scanf("%d", &a);// printf("Enter the second value:");// scanf("%d", &b);if(a>b)printf("a is greater than b"); else printf("a is less than or equal to b"); return 0; }
Output:
a is less than or equal to b
### Comparing Three Numbers
The following example defines three integer variables and uses `if` to compare the three numbers. You can first look at the logic diagram:
!(#)
## Example
#includeint main(){int a, b, c; a = 11; b = 22; c = 33; if(a>b&&a>c)printf("%d is the largest", a); else if(b>a&&b>c)printf("%d is the largest", b); else if(c>a&&c>b)printf("%d is the largest", c); else printf("Two or three values are equal"); return 0; }
Output:
33 is the largest
[ C Examples](#)
YouTip