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

A program to get marks of any 5 subjects and to get total marks with percentage and division.

//Write a program to get marks of any 5 subjects and to get total marks with percentage and division.
#include<stdio.h>
#include<conio.h>
void main()
{
int marks_english,marks_math,marks_account,marks_cscience,marks_economics;
int total_marks;
float percentage;
printf("enter marks of all subjects \n");
printf("enter marks for english\n");
scanf("%d",&marks_english);
printf("enter marks for mathematics\n");
scanf("%d",&marks_math);
printf("enter marks for account\n");
scanf("%d",&marks_account);
printf("enter marks for cscience\n");
scanf("%d",&marks_cscience);
printf("enter marks for economics\n");
scanf("%d",&marks_economics);
if(marks_english>=40 && marks_math>=40 && marks_account>=40 && marks_cscience>=40 && marks_economics>=40)
  {
     printf("u have passed!!\n and \n");
      total_marks=marks_english+marks_math+marks_account+marks_cscience+marks_economics;
      percentage=(float) total_marks/5;
       if(percentage>=75)
           {
               printf("you have got %f percentage with distinction!!\n",percentage);
            }
      elseif(percentage>=60 && percentage<75 )
           {
               printf("you have got %f percentage with first division!!\n",percentage);
            }
      elseif(percentage>=55 && percentage<60 )
           {
               printf("you have got %f percentage with second division!!\n",percentage);
            }
       elseif(percentage>=40 && percentage<55 )
           {
               printf("you have got %f percentage with third division!!\n",percentage);
            }
   }
    
else
 {
printf("sorry, you have failed the exam.\n"); 
 printf("so there is no total and percentage with division for you.\n Try hard next time.\n");   
  } 
printf("thank you!!!!\n");
getch();
}

Write a program to read annual salary of an employee and decide tax withheld as follows.

//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%
#include<stdio.h>
#include<conio.h>
void main()
{
float annual_salary;
float total_tax;
printf("enter total annual salary \n");
scanf("%f",&total_sales);
if(annual_salary<=100000)
    {
         total_tax=0; 
         printf("total tax to be paid=Rs. 0\n");
    }
elseif(annual_salary>100000 &&annual_salary<=150000)
    {
         total_tax=annual_salary*0.15
         printf("total tax to be paid=Rs. %f\n",total_tax);
    }
elseif(annual_salary>150000)
    {
          total_tax=annual_salary*0.25
          printf("total tax to be paid=Rs. %f\n",total_tax);
    } 
printf("thank you!!!!\n");
getch();
}

Write a program to input cost price and selling price and determine whether there is loss or profit.

//Write a program to input cost price and selling price and determine whether there is loss or profit.
#include<stdio.h>
#include<conio.h>
void main()
{
float selling_price,cost_price;
printf("enter cost price \n");
scanf("%f",&cost_price);
printf("enter selling price \n");
scanf("%f",&selling_price);
if(selling_price>cost_price)
    {
          printf("there is profit\n");
          printf(" and profit is=%f\n",selling_price-cost_price);
    }
  else
    {
         printf("there is loss");
         printf(" and loss is=%f\n",cost_price-selling_price);

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

Write a program to read age of person and find out the category among following according to age.

//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

#include<stdio.h>
#include<conio.h>
void main()
{
float age_person;
printf("enter your age \n");
scanf("%f",&age_person);
if(age_person>=0 && age_person<=12)
    {
          printf("Your are child\n");
    }
elseif(age_person>12 && age_person<=19)
    {
          printf("Your are teenage\n");
    }
elseif(age_person>19 && age_person<=30)
    {
          printf("Your are in adult life\n");
    }    
elseif(age_person>30 && age_person<=50)
    {
          printf("Your are passing your mature life now\n");
    }
elseif(age_person>50)
    {
          printf("Your are now an old person\n");
    }
printf("thank you!!!!\n");
getch();
}

A company pays its employee on hourly basis.If an employee works for 8hrs 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.

//A company pays its employee on hourly basis.If an employee works for 8hrs 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.
#include<stdio.h>
#include<conio.h>
void main()
{
float total_working_hrs,extra_hrs;
float total_salary;
printf("enter your total working hours \n");
scanf("%f",&total_working_hrs);
if(total_working_hrs<=8)
    {
           total_salary=total_working_hrs*100
          printf("total salary=Rs. %f\n",total_salary);
    }
elseif(total_working_hrs>8)
    {
         extra_hrs=total_working_hrs-8;
          total_salary=extra_hrs*120+8*100;
         printf("the total salary earned=%f\n",total_salary);
      }

getch();
}


A company provides commission on the basis of total sales. Find commission.

//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
#include<stdio.h>
#include<conio.h>
void main()
{
float total_sales;
float total_commission;
printf("enter total sales \n");
scanf("%f",&total_sales);
if(total_sales<10000)
    {
          printf("total commission=Rs. 0\n");
    }
elseif(total_sales>=10000 && total_sales<=100000)
    {
         total_commission=total_sales*0.05;
         printf("the amount=%f\n",total_commission);
      }
elseif(total_sales>100000)
    {
        total_commission=total_sales*0.1;
         printf("the amount=%f\n",total_commission);
      }    
printf("thank you!!!!\n");
getch();
}

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




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.