Comparing the given two integers using the if conditional selection of the C syntax for greater than, less than or equal

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

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 conditional selection C syntax for greater than, less than or equal

To show: How to use the if statement for simple selection in C programming for greater than, less than or equal

 

 

// A simple if statement usage

#include <stdio.h>

 

int main (void)

{

int x, y;

 

// Input the 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");

}

if (x > y)

{

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

}

if (x < y)

{

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

}

printf("\n\n");

return 0;

}

 

Output examples:

 

Input an integer value for x: 100

Input an integer value for y: 99

x is greater than y

Press any key to continue . . .

 

 

 

Input an integer value for x: 45

Input an integer value for y: 70

x is smaller than y

Press any key to continue . . .

 

 

 

Input an integer value for x: 77

Input an integer value for y: 77

x is equal to y

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index