if (test expression)
{
statement 1;
…...............
statement n;
}
statement x;
Write a program to print the highest number.
#include <stdio.h>
void main()
{
int n;
printf("Enter a number:");
scanf("%d", &n);
printf ("The entered number %d", n);
if (n>100)
printf ("You entered a higher number");
}
if (expression)
Statement 1;
else
Statement 2;
#include <stdio.h>
void main()
{
int yr;
clrscr();
printf("Enter a year:");
scanf("%d", &yr);
if ((yr%4 == 0) && ((yr%100 !=0) || (yr%400==0)))
printf("It's a leap year...!!!!");
else
printf ("It's not a leap year....!!!");
}
if (test expression 1)
{
statement block 1;
}
else if (test expression 2)
{
statement block 2;
}
....................
else
{
statement block x;
}
statement y;
#include <stdio.h>
void main()
{
int n1=10, n2=30, n3=75;
if (n1>n2 && n1>n3)
printf("%d is the largest number",n1);
if(n2>n1 && n2>n3)
printf("%d is the largest number", n2);
else
printf("%d is the largest number", n3);
}
switch (expression)
{
case expression 1: statement 1;
statement 2;
............
statement n;
break;
case expression 2: statement 1;
statement 2;
..........
statement n;
break;
default: statement 1;
statement 2;
...........
statement n;
}
#include <stdio.h>
void main( )
{
char ch;
printf("Enter any character:");
scanf("%c", &ch);
switch(ch)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
printf("%c is a vowel",ch);
break;
default:
printf("%c is not a vowel", ch);
}
}