You are on page 1of 2

#include <stdio.

h> //scanf , printf

//compile with gcc -std=c99 filename.c
//compile with newer c standart gcc -std=c11 filename.c
int main(){

//compare operators
// >, <, ==,<=,>=,!=
//comparisons return 1 if true and 0 if false

int num1=1,num2=2;

printf("is 1>2 : %d\n",num1>num2);

//if are multiple conditions that are true,
//only first true condition code will execute
if(num1>num2){
printf("%d is grater than %d\n",num1,num2);
}
else if(num1<num2){
printf("%d is lesser than %d\n",num1,num2);
}
else
{
printf("%d is equal to %d\n",num1,num2);
}

//relational operators
// && and
// || or
// ! not: eg !0 is 1 ; !1 is 0

int custAge=38;
if(custAge>21 && custAge<35)printf("They are welcome\n");
else printf("They are not welcome\n");

printf("\n");
printf("! turns a true into false: %d\n",!1);

printf("\n");
//missed less than 10 days work AND
//has over 30000 OR
//Signed up more than 30 new customers

int bobMissedDays=8,bobTotalSales=24000,bobNewCust=32;
if(bobMissedDays<10 &&bobTotalSales>30000 || bobNewCust>30){
printf("Bob gets a raise\n");
}
else{
printf("Bob doesnt get a raise\n");
}
printf("\n");

//conditional operator
int customerAge =38;

char * legalAge=(customerAge>21)? "true" : "false";

printf("is custormer legal age? : %s\n",legalAge);
printf("\n");

int numOfProducts=10;
printf("I bought %s products\n",(numOfProducts>1)?"many":"one");

}