Condi
Condi
1. if
2. if else
3. else if
4. nested if
5. switch case
Ex:
if(a<b)
{
...
}
//if statement:
#include<stdio.h>
int main()
{
int age;
printf("\nEnter the age:");
scanf("%d",&age);
if(age>=18)
{
printf("\nEligible to vote");
}
if(age<18)
{
printf("\nNot Eligible to vote");
}
return 0;
}
//if statement:
#include<stdio.h>
int main()
{
int num;
printf("\nEnter the number:");
scanf("%d",&num);
if(num%2==0)
{
printf("\nThis is an Even");
}
if(num%2!=0)
{
printf("\nThis is an Odd");
}
return 0;
}
//if else statement: if it is true means will be executed the true statements,if it
is false means will be
//executed the else statements.
#include<stdio.h>
int main()
{
int age;
printf("\nEnter the age:");
scanf("%d",&age);
if(age>=18)
{
printf("\nWelcome to vote.");
}
else
{
printf("\nNot Eligible to vote.");
}
return 0;
//Leap year:
#include<stdio.h>
int main()
{
int year;
printf("\nEnter the year:");
scanf("%d",&year);
if(year%4==0)
{
printf("\nThis is a Leap year");
}
else
{
printf("\nThis is not a Leap year");
}
return 0;
#include<stdio.h>
int main()
{
int num;
printf("\nEnter the number:");
scanf("%d",&num);
if(num%2==0)
{
printf("\nThis is an Even value");
}
else
{
printf("\nThis is an Odd value");
}
return 0;
return 0;
}
//switch case: more than one option we can used by case number.
// break keyword for termination in case block.
//should used switch keyword.
#include<stdio.h>
int main()
{
int opt,a,b,c,i,n;
start:
printf("\n1.Addition");
printf("\n2.Product");
printf("\n3.Even");
printf("\n4.Odd");
printf("\n5.Exit");
printf("\nEnter the choice:");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\nEnter the values of a and b:");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nAdd=%d",c);
break;
case 2:
printf("\nEnter the values of a and b:");
scanf("%d%d",&a,&b);
c=a*b;
printf("\nProduct=%d",c);
break;
case 3:
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nThe Even values are:");
for(i=0;i<=n;i++)
{
if(i%2==0)
{
printf("\n%d",i);
}
}
break;
case 4:
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nThe Odd values are:");
for(i=0;i<=n;i++)
{
if(i%2!=0)
{
printf("\n%d",i);
}
}
break;
case 5:
exit(0);
break;
default:
printf("Invalid choice.");
goto start;
}
return 0;
//Continue statement:
#include<stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<=10;i++)
{
sum+=10;
if(i==5)
{
continue; //skip and continue the process
}
printf("\n%d",sum);
}
return 0;
}
//switch case- we can be used more than one option by case number.
#include<stdio.h>
int main()
{
int a,b,c,i,n,no,x=8;
do
{
printf("\n----------------------------------------");
printf("\n1.Addition");
printf("\n2.Product");
printf("\n3.Even");
printf("\n4.Odd");
printf("\n5.Exit");
printf("\nEnter the choice:");
scanf("%d",&no);
switch(no)
{
case 1:
printf("\nEnter the a and b values:");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nAdd=%d",c);
break;
case 2:
printf("\nEnter the a and b values:");
scanf("%d%d",&a,&b);
c=a*b;
printf("\nMultiply=%d",c);
break;
case 3:
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nThe Even values are:");
for(i=0;i<n;i++)
{
if(i%2==0)
{
printf("\n%d",i);
}
}
break;
case 4:
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nThe Odd values are:");
for(i=0;i<n;i++)
{
if(i%2!=0)
{
printf("\n%d",i);
}
}
break;
case 5:
exit(0);
default:
printf("\nInvalid choice");
break;
}
}
while(x==8);
return 0;
}