Comparing the two given integers using the if-else C syntax for greater than, less than or equal

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Comparing the given two integers using the if-else C syntax for greater than, less than or equal

To show: How to use the if-else statements to compare two given integers in C programming for greater than, less than and equal

// Demonstrates the C if-else statement

#include <stdio.h>

int main(void)

{

int x, y;

// Input two values to be tested

printf("\nInput an integer value for x: ");

// read and store those inputs

// scanf("%d", &x);

scanf_s("%d", &x, 1);

printf("Input an integer value for y: ");

// scanf("%d", &y);

scanf_s("%d", &y, 1);

// Test values and print result

if (x == y)

{

printf("\nx is equal to y");

}

else

if (x > y)

{

printf("\nx is greater than y ");

}

else

{

printf("\nx is smaller than y ");

}

printf("\n\n");

return 0;

}

Output examples:

Input an integer value for x: 30

Input an integer value for y: 20

x is greater than y

Press any key to continue . . .

Input an integer value for x: 10

Input an integer value for y: 40

x is smaller than y

Press any key to continue . . .

Input an integer value for x: 80

Input an integer value for y: 80

x is equal to y

Press any key to continue . . .