C Program to Compare Two Integers
In this c programming example we will learn how to compare two integeres.
Algorithm
- Take two integers from user by printf() function
- These two integer values we will assign to a, b by scanf() function
- Now we will compare these two varaibles a,b with if condition
- If a is greater than b then if condition will execute and print the result as "a is greate than b"
- If we gives small value for a then else condition will executes and print result as "a is not greate than b"
Simple C example to compare two integers
#include <stdio.h>
int main() {
int a, b;
printf("Enter number a : ");
scanf("%d", &a);
printf("Enter number b : ");
scanf("%d", &b);
if(a > b)
printf("a is greater than b");
else
printf("a is not greater than b");
return 0;
}
|
Output
Enter number a : 10
Enter number b : 3
a is greater than b