Operators and branching

Let's start with operators so the list starts now...

  1. Mathematical:+,-,*,/%
  2. Relational:<,<=,>=,==,!=
  3. Logical: AND(&&)&OR(||)
  4. Unary operator:++(inceremant e.g.i++=i+1),--(e.g.i--=i-1)
then the next topic is branching or condition testing:
if keyword is used for contion testing

e.g.  A C program for if:
if (avg>=75)
{
printf("Congrats you secured first divison");
}

Similarly, else and else if can also be tested

e.g. A C program to find the biggest number between three numbers:

#include <stdio.h>

int main()
{
int a,b,c;

printf("Enter three numbers");
scanf("%d%d%d",&a,&b&c);

if(a>b&&a>c)
{
printf("A is the largest among three numbers"); 
// if a is big than b and c then its the largest
}

else if(b>c&&b>a)
{
printf("B is the largest among three numbers"); 
// if b is big than a and c then its the largest
}
else
{
printf("C is the largest among three numbers"); 
// After checking the over condition it becomes obvious that c is the largest so no need to check it again
}

getch(); //if using turbo c++ to keep the output page displayed

}

remember in else no condition is tested it remains blank
if can exist without else but else cannot and else if can also exist...

so here is my GitHub link if you wanna see some programs:https://github.com/aditya0072001/Program




Comments

Popular posts from this blog

C++ programming toll plaza simulation program

C++ program to give you hug(pun intended)