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

Write a program to read time in hours and displays different message

//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
#include<stdio.h>
#include<conio.h>
void main()
{
float time;
printf("enter value time in 24 hr format\n");
scanf("%f%",&time);
if(time>=0 && time<=12)
{
printf(Good morning man!!!\n");
}
elseif(time>12 && time<=18)
{
printf(Good evening man!!!\n");
}
elseif(time>18 && time<=24)
{
printf("good night");
}
getch();
}                                                                                                                 
            

a program to add two times in the format of hrs:minutes:seconds

// a program to add two times.
// e.g.
 // 2:50:20+2:40:12=5:30:32

#include<stdio.h>
#include<conio.h>
void main()
{
int hrs1,mns1,secs1;
int hrs2,mns2,secs2;
int hrs,mns,secs;
int real_hrs,real_mns,real_secs;
printf("enter first time\n");
printf("enter first hrs\n");
scanf("%d",&hrs1);
printf("enter minutes\n");
scanf("%d",&mns1);
printf("enter seconds now\n");
scanf("%d",&secs1);
printf("------------------\n");
printf("enter second time\n");
printf("enter first hrs\n");
scanf("%d",&hrs2);
printf("enter minutes\n");
scanf("%d",&mns2);
printf("enter seconds now\n");
scanf("%d",&secs2);
secs=secs1+secs2;
if(secs<60)
   {
     real_secs=secs1+secs2;
  }
else if(secs>=60)
   {
     real_mns=secs/60;
     real_secs=secs%60;
   }
mns=mns1+mns2;
if(mns<60)
   {
     real_mns=real_mns+mns1+mns2;
  }
else if(mns>=60)
   {
     hrs=mns/60;
     real_mns=mns%60;
   }
real_hrs=hrs1+hrs2+hrs;
printf("hrs=%d\n",real_hrs);
printf("minutes=%d\n",real_mns);
printf("seconds=%d\n",real_secs);
getch();
}

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

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