So sánh hai số nguyên
Viết chương trình nhập vào hai số nguyên a và b rồi so sánh hai giá trị của hai số đã nhập.nguyenthanhtruong
c_cpp
2 years ago
1.0 kB
14
Indexable
//Write a program that allows user to enter two integers called a and b then compares the values
//of the two numbers entered.
//Example 1: Please enter the first number: 9
//Please enter the second number: 5
//Comparison results: 9 is greater than 5
//Example 2: Please enter the first number: 3
//Please enter the second number: 18
//Comparison results: 3 is less than 18
//Example 3: Please enter the first number: 13
//Please enter the second number: 13
//Comparison results: both numbers are equal
#include <stdio.h>
#include <math.h>
int main() {
int a, b;
printf("Please enter the first number: ", a);
scanf("%d", &a);
printf("Please enter the second number: ", b);
scanf("%d", &b);
if (a > b) {
printf("Comparison results: %d is greater than %d\n", a, b);
}
else if (a < b) {
printf("Comparison results: %d is less than %d\n", a, b);
}
else {
printf("Comparison results: both numbers are equal", a, b);
}
return 0;
}
Editor is loading...
Leave a Comment