-->

if..else program collection

11) Write a program to get marks of any 5 subjects and to get total marks with percentage and division.
                                                                                                                          solution is here

12) Write a program to read annual salary of an employee and decide tax withheld as follos.
         salary                                          tax
            <=100000                                0%
           upto 150000                              15%
          above 150000                             25%
                                                                                                                        click to see solution

13)Write a program to input cost price and selling price and determine whether there is loss or profit
                                                                                                                       click to see solution  

14)Write a program to read age of person  and find out the category among following according to age.
           category                                         age
            child                                            0 to 12
            teenage                                         13 to 19
           adult life                                      20 to 30
           mature life                                   31 to 50
          old age                                         over 50
                                                                                                                            click to see solution

15) A company pays its employee on hourly basis.If an employee works for 8rs hours he gets  100/hr
, and 120/hr for additional hours.Write a program to read working hours of an employee and calculate total salary.
                                                                                                                            click to see solution


16)Write a program to display name of day on the basis of entered number
. for example, 2 for Monday.                                                                                click to see solution
                                                                                                                           
17) A company provides commission on the basis of total sales as follows.

         sales<10000-------------------------------->no commission
         sales >=10000 and <100000------------->5% commission
          sales>100000                  ---------------->10%commission
                                                                                                                           click to see solution

18)Write a program to get greatest value among three numbers using nested if.
                                                                                                                            click to see solution

19)A book store gives 10% discount to  a buyer if the buyer buys books more than Rs 1000.Write a program to asking the cost of books and calculate discount amount.
                                                                                                                            click to see solution

click to next page for more programs' collection

Write a program to know a triangle is equilateral or not.

//a program to know a triangle is equilateral or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;                          // x,y z are sides
printf("enter 3 sides\n");
scanf("%d%d%d",&x,&y,&z);
if(x==y && y==z)
{
printf("it is an equilateral  triangle");
}
else
{
printf("it is not");
}
getch();
}

note:
you can use also use angle concept.

Write a program to know a triangle is right angled or not

//a program to know a triangle is right angled or not
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;                          // x,y z are angles
printf("enter 3 angles\n");
scanf("%d%d%d",&x,&y,&z);
if(x==90 || y==90 || z==90)
{
printf("it is right angled triangle");
}

else
{
printf("it is not");
}
getch();
}

Write a program to get sum or product or difference or quotient of two numbers using switch.

//program to get sum or product or difference or quotient of two numbers using switch.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice;
int number1,number2;
printf("enter your choice\n");
scanf("%d",&choice);
 switch(choice)
          {
                  case 1:
                            printf("we are going to sum two numbers\n");
                            printf("enter two numbers\n");
                            scanf("%d%d",&number1,&number2);
                           printf("the sum=%d",number1+number2);
                 break;
               case 2:
                            printf("we are going to get difference of two numbers\n");
                            printf("enter two numbers\n");
                            scanf("%d%d",&number1,&number2);
                            printf("the sum=%d",number1-number2);
                 break;

               case 3:
                            printf("we are going to get product of two numbers\n");
                            printf("enter two numbers\n");
                            scanf("%d%d",&number1,&number2);
                           printf("the sum=%d",number1*number2);
                 break;
             case 4:
                            printf("we are going to get quotient of two numbers\n");
                            printf("enter two numbers\n");
                            scanf("%d%d",&number1,&number2);
                           printf("the sum=%d",number1%number2);
                 break;

              default:
                            printf("sorry, not a valid input\n");
                            printf("thank u, terminating....\n");
          }
getch();
}

note:
here, you can use 'char' data type instead 'int' and you can input data before switch statement as well.

                         



Write a program to get smallest number among three numbers.

//a program to get smallest number among three numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
printf("enter 3 numbers\n");
scanf("%d%d%d",&x,&y,&z);
if(x<y && x<z)
{
printf("x is smallest");
}
elseif(y<x && y<z)
{
printf("y is smallest\n");
}
else
{
printf("z is smallest");
}
getch();
}

Write a program to know a number entered by you lies between two values/range or not

//a program to know a number entered by you lies between two values/range or not
#include<stdio.h>
#include<conio.h>
void main()
{
float n,range_v,range_v1;
printf("enter a number to check\n");
scanf("%f",&n);
printf("enter range values");
scanf("%f%f",&range_v,&range_v1);
if(n>range_v && n<range_v1)
{
printf("it lies in range");
}
else 
{
printf("it does not\n");
}
getch();
}

Write a program to get greatest number among three numbers.

//a program to get greatest number among three numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
printf("enter  numbers\n");
scanf("%d%d%d",&x,&y,&z);
if(x>y && x>z)
{
printf("x is greatest");
}
elseif(y>x && y>z)
{
printf("y is greatest\n");
}
else
{
printf("z is greatest");
}
getch();
}