Share PSCP Lab Assignment 2
Share PSCP Lab Assignment 2
1 Enter 4-digit number through keyboard. Write a program to obtain the sum of 1st and last digits of this number.
2 Enter a year through keyboard. Write a program to determine whether the year is leap year or not. Use logical
operators && and ||.
3 Write a program that will take three numbers from keyboard and find the maximum of these numbers. Then
check whether the maximum number is even or odd.
6 The mark price and discount are entered through keyboard. Sometimes seller gets profit of x % or some time
loss of y % depends on discount. Write a program to determine whether the seller has made profit or incurred
loss. Also determine how much profit he made or loss incurred. Enter the cost price also through key board.
7 Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the
number is equal to the number itself, then the number is called an Armstrong number. For example 153=
(1*1*1) + (5*5*5) + (3*3*3).
8 There are 9000 people in a town whose population increases by 15% each year. Write a program that displays
the annual population and determines the number of years it will take for the population to surpass 50000.
9 Write a program to print the sum of digits of any positive number
10 Write a program to receive Cartesian coordinates (x,y) of a points and convert them into polar co-
ordinates(r,θ).
11 Write a program to receive values of latitude(L1,L2) and longitude (G1,G2), in degrees, of two places on the
earth and output the distance(D) between then in nautical miles.
12 Wind chill factor is the felt air temperature on exposed skin due to wind. The wind chill temperature is always
lower than the air temperature. Write a program to calculate the wind chill factor.
13 If the value of an angle is input through the keyboard, write a program to print all its Trigonometric ratios.
14 Find the gcd and lcm of given two numbers
15 Write a program to find the sum of first n terms of series:
16 Write a program to accept a number and find sum of its individual digits repeatedly till the result is a single
digit. For example, if the given number is 4687 the output should be 7.
17 Write a program to get following output
ABCDEFGFEDCBA 1
ABCDEF FEDCB A
ABCDE EDCB A 1 1 *
ABCD DCB A
1 2 1 * * *
ABC CBA 1 3 3 1 * * * * *
AB BA 1 4 6 4 1 * * * * * * *
A
1 3 3 1 * * * * *
A
1 2 1 * * *
1 1 *
1
18 An equation of the form ax^2+bx+c=0 is known as quadratic equation. The values of x that satisfy the
equation are known as the roots of the equation. Write a program to find out the roots of the quadratic equation
19 Write a program to find out the sum of the following series (up-to 30th term):
……………….
1-Factorial of a number
2-Prime or not
3-Odd or even
4. Nth Fibonacci number
5-Exit
Once a menu item is selected the appropriate option should be taken and once this option is finished, the menu
should reappear .Unless the user selects the Exit option the program should continue work.
21 A user enters integers until end of input and wants to find the largest number in the list of integers entered and
the number of times it was entered. For example, if the input is 5, 2, 15, 3, 7, 15, 8, 9, 5, 2, 15, 3, and 7, the
largest is 15 and is repeated 3 times. Write an algorithm to compute frequency of the largest of the integers
entered without storing them. Convert the algorithm to a function that displays the integers read and returns the
largest number and its frequency.
22 Write a program that reads an integer -n (decimal number system) and convert this decimal number to Binary,
Octal, and Hexadecimal form.
23 Given 3-angles. write a program to check whether they form a triangle or not (A+B+C =180). If yes check
whether triangle is scalen, equilateral, isoceless or right angled triangle.
24 The Fibonacci numbers Fn are defined as follows. F 0 is 1, F1 is 1 and Fi+2=Fi+Fi+1 i=0,1,….n Write a program to
find the Fibonacci value of the given number.
25 Write a program to print all the ASCII values and their equivalent characters using a while loop.
26 A way to calculate the value of π is based on the use of a series defines as follows(N- number of terms). Write
a program to find π value (up to n terms and display the result by correcting it to three decimal places):
27 Write a program that accepts a year written as a four-digit numeral and outputs the year written in Roman
numerals. Important Roman numerals are V –5 , X-10 , L-50 , C-100, D-500 and M-1,000.
28 Write a function power(a,b) , to calculate the value of a raised to b.
29 A positive integer is entered through the keyboard, write a function to find the binary equivalent of this
number:
(i) without using recursion
(ii) using recursion
30 Write a program for towers of Hanoi, using recursive function