//1. C Program to find the biggest and smallest among 4 numbers using nested if.
#include<stdio.h>
void main()
{
int a=400,b=300,c=20,d=200,big,small; //Declare variables and initialize them.
clrscr(); //Clear the screen.
if((a>b && a>c) && a>d) //Check whether a is greater than b,c and d.
{
big=a;
if(b<c && b<d) //Check whether b is lesser than c and d.
small=b;
else if(c<d) //Check whether c is lesser than d.
small=c;
else
small=d;
}
else if(b>c && b>d) //Check whether b is greater than c and d.
{
big=b;
if(a<c && a<d) //Check whether a is lesser than c and d.
small = a;
else if(c<d) //Check whether c is lesser than d.
small = c;
else
small = d;
}
else if(c>d) //Check whether c is greater than d.
{
big=c;
if(a<b && a<d) //Check whether a is lesser than b and d.
small=a;
else if(b<d) //Check whether b is lesser than d.
small=b;
else
small=d;
}
else
{
big=d;
if(a<b && a<c)
small=a;
else if(b<c)
small=b;
else
small=c;
}
printf("Biggest Number=%d \t Smallest Number=%d",big,small);
getch();
}
#include<stdio.h>
void main()
{
int a=400,b=300,c=20,d=200,big,small; //Declare variables and initialize them.
clrscr(); //Clear the screen.
if((a>b && a>c) && a>d) //Check whether a is greater than b,c and d.
{
big=a;
if(b<c && b<d) //Check whether b is lesser than c and d.
small=b;
else if(c<d) //Check whether c is lesser than d.
small=c;
else
small=d;
}
else if(b>c && b>d) //Check whether b is greater than c and d.
{
big=b;
if(a<c && a<d) //Check whether a is lesser than c and d.
small = a;
else if(c<d) //Check whether c is lesser than d.
small = c;
else
small = d;
}
else if(c>d) //Check whether c is greater than d.
{
big=c;
if(a<b && a<d) //Check whether a is lesser than b and d.
small=a;
else if(b<d) //Check whether b is lesser than d.
small=b;
else
small=d;
}
else
{
big=d;
if(a<b && a<c)
small=a;
else if(b<c)
small=b;
else
small=c;
}
printf("Biggest Number=%d \t Smallest Number=%d",big,small);
getch();
}
No comments :
Post a Comment