You are on page 1of 5

(i) If statement

General format : if(condition)

Statements ;

Example :

/* elegible to vote */

#include<stdio.h>

Int main()

int age ;

printf(“enter your age”);

scanf(“%d”,&age);

if(age>=18)

printf(“ elegible to vote”);

return 0;

ii)if else statement

General format

if (condition)

statement 1;

else

statement2;

/* to find odd and even number*/

#include<stdio.h>

int main()

int number;

printf("enter number");

scanf("%d",&number);
if(number%2==0)

printf("it is an even number");

else

printf("it is an odd number");

return 0;

Nested if-else statement

General format

if (codition1)

if(condition2)

statement1;

else

Statement2;

else

statement 3;

Statement n;

/* to find biggest of three numbers */

#include<stdio.h>

int main()

int a,b,c,big;
printf("\n enter three numbers :");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

if(a>c)

big=a;

else

big=c;

else

if(b>c)

big=b;

else

big=c;

printf("\n biggest number is %d",big);

return 0;
}

Else if ladder

if(condition1)

statement1;

else if (condition2)

statement2;

else if(condition3)

statement3;

else if (condition n )

statement n ;

else

default statement ;

statement X

/* to find lower case or upper case letter or to check whether athe character is not an alphabetic
character */

#include<stdio.h>

int main()

{char a ;

printf("enter an alphabetic character:");

scanf("%c",&a);

if(a>=65 && a<=90)

printf("it is an upper case alphabet");

else if (a>=97 && a<=122)

printf("it is a lowercase alphabet ");

else

printf("it is not an alphabetic character ");

return 0 ;

You might also like