# Relational and Logical Operators

This is a discussion on Relational and Logical Operators within the C Programming forums, part of the General Programming Boards category; Hello all I have a small problem with these operators as they dont seem to give the answer to what ...

1. ## Relational and Logical Operators

Hello all

I have a small problem with these operators as they dont seem to give the answer to what i would expect them to,
any help with a decent explination would be appreciated

Heres my code#include <stdio.h>

int main()
{
int i;
int j;

printf("Enter first number"); /*number entered will be 5 */
scanf("%d", &i);
printf("Enter first number"); /*number entered will be 0 */
scanf("%d", &j);

printf("i < j %d\n", i<j); /*expected answer as 5 is greater than 0 "TRUE therefor 1" */

printf("i <= j %d\n", i<=j); /*expected answer as 5 is greater than 0 "TRUE therefor 1" */

printf("i == j %d\n", i==j); /*expected answer as 5 is not equal to 0 "FALSE therefore 0 */

printf("i > j %d\n", i>j); /*expected answer as 5 is not less than 0 "TRUE 0" */

printf("i >= j %d\n", i>=j); /*expected answer as 5 is not less than or equal to 0 "TRUE 0" */

When the program is run the following output is displayed and I dont understand why ??

Enter no 5
Enter no 0

i > j 0
i <= j 0
i == j 0
i > j 1
i >= j 1

press any key to continue ...

Think my logic here is up the pole but any help would be great

Thanks
GSLR

2. Ok - at the start of the program you enter:

i = 5
j = 0

therefore:
i < j is FALSE as 5 is not LESS than 0 - Therefore FALSE or 0
Code:
`printf("i < j %d\n", i<j); /*expected answer as 5 is greater than 0 "TRUE therefor 1" */`
< - Less than operator
<= - Less than or equal to operator
== - Equal to operator
> - Greater than operator
>= - Greater than or equal to operator
!= - Does not equal operator

The programs output is correct. (i > j 0 with this exception which I think was a typo on your behalf )

3. ## thanx

thanx

I realised me error after i posted

Looks like i need a course in maths again !!!