Monday, 18 September 2017 06:47

## C-if else Program

Written by
Rate this item

Write a program to check equivalence of two numbers. Use the if statement.

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Int  m, n;

Clrscr ( );

Printf (“\n Enter Two Numbers  :”);

Scanf (“%d  %d”, &m, &n);

If (m-n==0)

Printf (“\n Two numbers are equal. “);

getch( );

}

OUTPUT:

Enter Two Numbers  :  5  5

Two numbers are equal.

Write a program to check whether the candidate’s age is greater than 17 or not. If yes, display

Message ‘Eligible for Voting’.

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Int  age;

Clrscr ( );

Printf (“\n Enter age  :”);

Scanf (“%d, &age);

If (age>17)

Printf (“\n Eligible for Voting.”);

getch ( );

}

Write a program using curly braces in the if block. Enter only the three numbers and calculate their sum and multiplication.

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Int a, b, c, x;

Clrscr ( );

Printf (“\nEnter Three Numbers:”);

X=scanf (“%d %d %d”, &a, &b, &c);

If (x==3)

{

Printf (“\n Addition  :  %d”, a,+b+c);

Printf (“\n Multiplication  :  %d”, a*b*c);

}

}

OUTPUT:

Enter Three Numbers:  1  2  4

Multiplication  :  8

After second time execution

Enter Three Numbers:  5  v  8

Read the values of a, b and c through the keyboard. Add them and after addition check if it is In the range of 100 and 200 or not. Print the separate message for each.

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Int  a, b, c, d;

Clrscr (“Enter Three Numbers a b c  :”);

Printf (“%d %d %d”, &a, &b, &c);

Printf (“a=%d b=%d c=%d”, a, b, c);

D=a+b+c;

If (d<=200 && d>=100)

Printf (“\nSum is %d which is in between 100 & 200”, d);

else

Printf (“\nSum is %d which is out of range”, d);

getch ( );

}

OUTPUT:

Enter Three Numbers a b c  :  50  52  54

A=50  b=52  c=54

Sum is 156 which is in between 100 & 200.

Write a program to calculate the square of those numbers only whose least significant Digit is 5.

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Int  s, d;

Clrscr ( )

Printf (“\n Enter  a  Number  :”);

Scanf (“%d, &s);

D=s %10;

If (d==5)

{

S=s/10;

Printf (“\n Square  =  % d%d”, s*s++,d*d);

}

Else

Printf (“\n Invalid Number”);

}

OUTPUT:

Enter  a  Number  :  25

Square  =  625

Write a program to calculate the salary of medical representative based on the sales. Sales.

Bonus And incentive to be offered to him will be based on total sales.

If the sale exceeds Rs.1, 00,000,Follow the particulars of Table 1 otherwise follow Table 2.

 TABLE Basic=Rs.  3000. Hra=20% of basic. Da=110% of basic. Conveyance=Rs. 500. Incentive=10% of sales. Bonus=Rs.  500. TABLE Basic=Rs.  3000. Hra=20% of basic. Da=110% of basic. Conveyance=Rs. 500. Incentive=5% of sales. Bonus=Rs.  200.

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Float bs, hra, da, cv, incentive, bonus, sale, ts;

Clrscr ( );

Printf (“\n Enter Total Sales in Rs.:”);

Scanf (“%f”, &sale);

If (sale>100000)

{

Bs=3000;

Hra=20  *  bs/100;

Da110  *  bs/100;

Cv=500;

Incentive=sale*10/100;

Bonus=500;

}

Else

{

Bs=3000;

Hra=20  *  bs/100;

Da=110  *  bs/100;

Cv=500;

Incentive=sale*5/100;

Bonus=200;

}

Ts=bs+hra+da+cv+incentive+bonus;

Printf (“\nTotal Sales  :  % f”, sale);

Printf (“\nBasic salary :  % f”’, bs)

Printf (“\nHra               :  % f”, hra);

Printf (“\nDa                 :  % f, da);

Printf (“\nConveyance : % f”, cv);

Printf (“\nIncentive      : % f”, incentive)

Printf (“\nBonus            : % f”, bonus);

Printf (“\nGross Salary : % f”, ts);

getch ( );

}

OUTPUT:

Enter Total Sales in Rs.  100000

Total Sales:  100000.00

Basic Salary:  3000.00

Hra:  600.00

Da:  3300.00

Conveyance:  500.00

Incentive:  10000.00

Bonus:  500.00

Gross Salary:  17900.00

Write a program to calculate energy bill. Read the starting and ending meter readings.Charges are as follows.

No. of Units    Consumed Rates in  (Rs.)

200  -  500                           3.50

100  -  200                           2.50

Less  than  100                   1.50

#include<stdio.h>

#include<conio.h>

Void main ( )

{

Int initial, final, consumed;

Float total;

Clrscr ( );

Printf (“\n Initial & Final Readings  :”);

Scanf (“%d  %d”,  &initial,  &final);

Consumed  =  final – initial;

If (consumed>=200  &&  consumed<=500)

Total=consumed  *  3.500;

Else if (consumed>=100  &&  consumed<=199)

Total= consumed  *  2.500;

Else if (consumed*1.50;

Printf (“Total bill for %d unit is %f”, consumed, total);

getche ( );

}

OUTPUT:

Initial  &  Final Readings  :  800  850 