Anda di halaman 1dari 10

1. Write a program to input three numbers (positive or negative).

If they
are unequal then
display the greatest number, otherwise display they are equal. The
program also
displays whether the numbers entered by the user are ‘All positive’,
‘All Negative’ or
‘Mixed numbers’.
Sample Input: 56, -15, 12
Sample Output: The Greatest number is 56
Entered numbers are mixed numbers.

//

0 0 0)

0 0 0)
Variable Type Use
a int to store the first number
b int to store th second number
c int to store the third number
gn int to store the greatest out of the three numbers

2. An air-conditioned bus charges fare from the passengers based on the


distance
travelled as per the tariff given below:
Distance Travelled Fare
Up to 10 km Fixed charge Rs. 80
11 km to 20 km Rs.6/km
21 km to 30 km Rs.5/km
31 km and above Rs.4/km
Design a program to input distance travelledby the passenger. Calculate
and display the
fare to be paid.

//

10)

80

10 20)

80+( 10)*6

20 30)

80+10*6+( 20)*5

80+10*6+10*5+( 30)*4
Variable Type Use
d int To store the distance travelled
f int To store the fare to be paid

3. The standard form of quadratic equation is given by:


ax2+bx+c=0, where d=b2-4ac, is known as discriminant that determines the
nature of
the roots of the equation as:

Condition Nature
if d>=0 Roots are real
if d<0 Roots are imaginary
Write a program to determine the nature and the roots of a quadratic
equation, taking
a,b,c as input. If d=b2-4ac is greater than or equal to zero, then
display ‘Roots are
real’, otherwise display ‘Roots are imaginary’.
The roots are determined by the formula as:
r1=-b+ b2-4ac , r2= -b – b2-4ac
2a 2a

//

1 2

4*
0)

1=(- 4* 1/2))/2*
2=(- 4* 1/2))/2*
1+" 2)
Variable Type Use
a int to store to value of a as in a quadratic
equation
b int to store to value of b as in a quadratic
equation
c int to store to value of c as in a quadratic
equation
d int to store to value of discriminant
r1 double to store the first root
r2 double to store the second root

4. Write a program using switch case to find the volume of a cube, a


sphere and a
cuboid. For an incorrect choice, an appropriate error message should be
displayed.
a) Volume of a cube
b) Volume of a sphere
c) Volume of a cuboid
//

1.
2.
3.

1:

2:

4/3.0)*(22/7)*

3:
Variable Type Use
ch int to store the choice of the user
s int to store the side of a cube
r int to store the radius of a sphere
l int to store the length of cuboid
b int to store the breadth of cuboid
h int to store the height of cuboid
v double to store the volume of cube or sphere or cuboid

1. Write a program to print Fibonacci series of n terms where n is input by


user:
0 1 1 2 3 5 8 13 24 .....
Variable Type Use
a int serves as a variable to print fibonacci series
b int serves as a variable to print fibonacci series
c int to store the values to be printed in fibonacci
series
n int to store the number of terms to be printed

Anda mungkin juga menyukai