-->
Showing posts with label if. Show all posts
Showing posts with label if. Show all posts

A program to calculate electricity bill for used hours/units

//The minimum charge for Nepal Electricity authority is Rs. 80 for 20 units consumed. If a  person //consumes more than that then s/he has to pay Rs. 7.25 per unit extra up to 100. If the person //consumes //more than 100 units then he has to pay 9.50 per unit. Write a 'C' program to calculate //bill.
#include<stdio.h>
#include<conio.h>
void main()
{
float total_units;
float total_amount;

printf("enter total units consumed\n");
scanf("%f",&total_units);
if(total_unit<=20)
    {
          printf("total amount to be paid=Rs. 80\n");
    }
elseif(total_unit>20 && total_unit<=100)
    {
         total_amount=80+7.25*(total_unit-20);
         printf("the amount=%f\n",total_amount);
      }
elseif(total_unit>100)
    {
         total_amount=80+9.5*(total_unit-20);
         printf("the amount=%f\n",total_amount);
      }  
printf("thank you!!!!\n");
getch();
}
                                                                                               

a program to calculate Income tax based on annual income according to given rules.

//Income tax is calculated on annual income according to following rules.
 //      salary                                  married                   unmarried
//up to 100000                               0%                          0%
//100000... 300000                        5%                          10%
//above    300000                          15%                        20%
#include<stdio.h>
#include<conio.h>
{
float annual_salary,income_tax;
char marital_status;
printf("enter you marital status\n");
printf("married(m) and\n");
printf("unmarried(u)\n");
scanf(" %c",&marital_status);
printf("now enter you annual income ?\n");
scanf("%f",&annual_income);
if((marital_status=='m')||(marital_status=='u)' && annual_salary<=100000)
     {
       income_tax=0*annual_salary;
       printf("tax amount=%f\n",income_tax);
      }
elseif((marital_status=='m') && (annual_salary>100000 && annual_salary<=300000)
     {
       income_tax=0.05*annual_salary;
       printf("tax amount=%f\n",income_tax);
      }
elseif((marital_status=='m') && (annual_salary>300000))
     {
       income_tax=0.15*annual_salary;
       printf("tax amount=%f\n",income_tax);
      }
elseif((marital_status=='u') && (annual_salary>100000 && annual_salary<=300000)
     {
       income_tax=0.10*annual_salary;
       printf("tax amount=%f\n",income_tax);
      }
elseif((marital_status=='u') && (annual_salary>300000)
     {
       income_tax=0.2*annual_salary;
       printf("tax amount=%f\n",income_tax);
      }
getch();
}




program to input number of passenger and destination through air.This program should print name,destination,number of passenger and total fare

//a program to input number of passenger and destination through air.This program should print //name,destination,number of passenger and total fare using following rate.
//Destination                                                                  Rate
//      Pokhara                                                                 Rs. 2400
//    Bharaiwa                                                                 Rs. 2500
//     Biratnagar                                                               Rs. 800
//     Bhadrapur                                                               Rs. 2550
#include<stdio.h>
#include<conio.h>
void main()
{

int no_passenger;
char name[200],destination[200];
float total_fare;
printf("enter total passenger\n");
scanf("%d",&no_passenger);
printf("enter passenger name\n");
gets(name);
printf("enter destination\n");
gets(destination);
if((strcmp(destination,Pokhara))==0)
{
total_fare= 2400*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);
}
elseif(((strcmp(destination,Bhairawa))==0)
{
total_fare= 2500*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);

}
elseif(((strcmp(destination,Biratnagar))==0)
{
total_fare= 800*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);

}
elseif(((strcmp(destination,Bhadrapur))==0)
{
total_fare= 2550*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);

}
getch();
}

if..else program collection

20)Write a program to read time in hours and displays following message.
       0 to 12                                                        Good morning
        12 to 18                                                     Good evening
        18 to 24                                                     Good night
                                                                                                                       click to see solution                      

21)calculate roots of quadratic equation (ax2+bx+c). Conditions to be taken into account are
          (b2-4ac)>0 and 2a>0
                                                                                                                        click to see solution

22)Write a program to add two times.
   e.g.
          2:50:20+2:40:12=5:30:32
                                                                                                                 click to see program

23)Nepal telecom calculates the bill according to following rule.
       minimum charge is Rs. 100 for 100 calls.
       if calls exceed 100 then charge is Rs. 1/call is added with 10% tax and 13% vat cumulatively on total amount. Write a 'C' program for this.

                                                                                                                    Click to see solution

24)The minimum charge for Nepal Electricity authority is Rs. 80 for 20 units consumed. If a  person consumes more than that then s/he has to pay Rs. 7.25 per unit extra up to 100. If the person consumes more than 100 units then he has to pay 9.50 per unit. Write a 'C' program to calculate bill.

                                                                                                                   Click to see program

25)Income tax is calculated on annual income according to following rules.
       salary                                  married                   unmarried
up to 100000                               0%                          0%
100000... 300000                        5%                          10%
above    300000                          15%                        20%
     
                                                                                                                 
                                                                                                                  Click to see solution

26)Write a program to input number of passenger and destination through air.This program should print name,destination,number of passenger and total fare using following rate.

       Destination                                                            Rate
      Pokhara                                                                 Rs. 2400
    Bharaiwa                                                                 Rs. 2500
     Biratnagar                                                               Rs. 800
     Bhadrapur                                                               Rs. 2550

                                                                                                                  Click to see solution


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 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 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();
}

Write a program to know two numbers entered by you are same or not.

//program to know two numbers entered by you are same or not.
#include<stdio.h>
#include<conio.h>
void main()
{
float n,n1;
printf("enter a number\n");
scanf("%f%f",&n,&n1);
if(n==n1)
{
printf("they are equal");
}
else
{
printf("they are not");
}
getch();
}