C/Language Basics/Operator Relation
Logical operator
#include<stdio.h>
main( ) {
int c1,c2,c3;
printf("enter value for c1, c2,c3");
scanf("%d%d%d",&c1,&c2,&c3);
if((c1 < c2)&&(c1<c3))
printf("\n c1 is less than c2 and c3");
if (!(c1< c2))
printf("\n c1 is greater than c2");
if ((c1 < c2)||(c1 < c3))
printf("\n c1 is less than c2 or c3 or both");
}
Relational and logical operations
#include <stdio.h>
int main(void)
{
int i, j;
printf("Enter i: ");
scanf("%d", &i);
printf("Enter j: ");
scanf("%d", &j);
/* relational operations */
printf("i < j %d\n", i < j);
printf("i <= j %d\n", i <= j);
printf("i == j %d\n", i == j);
printf("i > j %d\n", i > j);
printf("i >= j %d\n", i >= j);
/* logical operations */
printf("i && j %d\n", i && j);
printf("i || j %d\n", i || j);
printf("!i !j %d %d\n", !i, !j);
return 0;
}
Testing letters using and
/*Testing letters using and */
#include <stdio.h>
void main()
{
char letter =0; /* Stores an input character */
printf("Enter an upper case letter:");
scanf(" %c", &letter); /* Read the input character */
if ((letter >= "A") && (letter <= "Z")) /* Verify uppercase letter */
{
letter += "a"-"A"; /* Convert to lowercase */
printf("Your enter is %c.\n", letter);
}
else
printf("An uppercase letter please.\n");
}