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

A program to get greatest value among three numbers using nested if.

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

{
    if(y>x)
     {
     if(y>z)
        {
                printf("y is greatest");
         }
       else
      {
      printf(" z is greatest");
      }
   }
   else
   {
   printf("x is greatest");
   }
}
getch();
}                                                                                                      

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.

//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.
#include<stdio.h>
#include<conio.h>
void main()
{
float total_books_amount_bought;
float discount_amount;


printf("enter total books' amount purchased\n");
scanf("%f",&total_books_amount_bought);
if(total_books_amount_bought<1000)
    {
          printf("sorry, no discount we have for this much amount!\n")
     }
else(total_books_amount_bought>1000)
    {
         discount_amount=total_books_amount_bought-total_books_amount_bought*0.1;
         printf("the discount amount=%f\n",discount_amount);
      }   

printf("thank you!!!!\n");
getch();
}                                                                                                               

a program to calculate roots of quadratic equation (ax2+bx+c).

//calculate roots of quadratic equation (ax2+bx+c). Conditions to be taken into account are
// (b2-4ac)>0 and 2a>0
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
float x1,x2;
float root_value;
printf("enter value for a,b and c\n");
scanf("%f%f%f",&a,&b,&c);
root_value=pow(b,2)-4*a*c;
if(root_value>0 && a>0)
{
printf("roots are possible\n");
x1=(-b+sqrt(root_value))/2*a;
x2=(-b+sqrt(root_value))/2*a;
printf("first root/value=%f\n",x1);
printf("second root/value=%f",x2);
}
else
{
printf("real roots are not possible\n instead,");
printf("imaginary roots are possible");
}
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();
}

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