9 Pract
9 Pract
Write a program to input the time in hours, minutes and seconds and
print it in seconds.
For Example:
INPUT: Enter time in hours:
1
Enter time in minutes:
12
Enter time in seconds:
6
OUTPUT:
Time in seconds:4326
2. Write a program to input the Basic Pay of an employee and find the gross
pay of the employee for the following allowances and deductions.
Dearness Allowance = 25% of Basic Pay
House Rent Allowance=15% of Basic Pay
Provident Fund=8.33% of Basic Pay
Net Pay=Basic Pay + Dearness Allowance + House Rent Allowance
Gross Pay= Net Pay – Provident Fund
3. Write a program that outputs the results of the following evaluations
based on the number entered by the user.
i. Cube root of the number
ii. Absolute value of the number
iii. Square root of the number
iv. Random numbers between 0 and 1.
4. Write a program to input the three sides of a triangle and find the
perimeter and area of the triangle.
If a, b and c are the 3 sides then,
Perimeter=a+b+c
Area= s(s − a)(s − b)(s − c) where
s =( a + b + c)/2 .
5. Write a program to accept three sides of a triangle as parameter and
check whether it can form a triangle or not. If it forms a triangle, check
whether it is an acute angled, obtuse angled or right-angled triangle.
(Hint: To form a triangle, each side should be less the sum of the other
two sides..
a. To form an acute angled triangle the square of every side should
be less than the sum of the squares of the other two sides.
b. To form an obtuse angled triangle the square of any side should be
greater than the sum of the squares of the other two sides.
c. To form an right angled triangle the square of any side should be
equal to the sum of the squares of the other two sides.)
7. Write a menu driven class to accept a number from the user and check
whether it is a Palindrome or a Perfect number.
(a) Palindrome number- (a number is a Palindrome which when read in reverse
order is same as
read in the right order) Example: 11, 101, 151, etc.
(b) Perfect number- (a number is called Perfect if it is equal to the sum of its
factors other than the
number itself.) Example: 6=1+2+3
8. Write a program to find the sum of series, taking the value of ‘a’ and ‘n’ from
the user.
9. Write a program to input a number and check whether it is a Smith number
or not. Smith number is such a number, the sum of whose digits equals the
sum of the digits of its prime factors.
Smith number is a composite number in which the sum of its digits is
equal to the
sum of the digits of all its prime factors.
For Example 378 is a Smith Number as the sum of the digits of 378 are :
3+7+8 = 18. The prime
factors of 378 are: 2, 3, 3, 3, 7 ( sum = 2+3+3+3+7 = 18).
Similarly 22 is a Smith Number as the sum of the digits are : 2+2=4. The
prime factors of 22 are:
2 and 11 (Sum = 2+(1+1) = 4
Other Examples include 27, 58, 85, 94, 121, 166, 202, 265, etc.
Upto 45 No Tax
More than 45 but 75 or less 475.00
More than 75 but 125 or less 750.00
More than 125 but 200 or less 1225.00
More than 200 but 350 or less 1650.00
More than 350 2000.00
Write a program to input the water consumed annually in gallons and output
the tax payable.
14. Write a program to find the sum of 1st 10 numbers of Fibonacci series i.e.
1,1,2,3,5,8,13….
Fibonacci series is such a series which starts from 1 and 1, and subsequent
numbers are the sum of the previous two numbers.
15.Write a program to input an integer and remove all the even digits from it.
For Example,
INPUT: Enter an integer: 1234
OUPUT: 13
16. In an entrance examination, students have answered English, Maths and
Science papers. Write a program to calculate and display average marks
obtained by all the students. Take the number of students appeared and marks
obtained in all three subjects by every student along with the name as inputs.
1
21
321
4321
54321
(b)
12345
1234
123
12
1
19. Write a class with the name Area using method overloading that computes
the area of a parallelogram, a rhombus and a trapezium.
Formula: