PF Lab 1
PF Lab 1
Lab(1)
Problem 1:
Part 1: Write a program that prints numbers in increasing order within the range of 100 to 200
(inclusive).
Part 2: Write a program that prints even numbers within the range of 100 to 200 (inclusive).
Part 3:Write a program that prints odd numbers within the range of 100 to 200.
Part 4: Write a program that prints multiples of 5 within the range of 100 to 200 (inclusive).
Problem 2:
Part 1; Write a program that prompts the user to enter a temperature in Celsius (C) from the keyboard.
The program should then convert the temperature to both Fahrenheit (F) and Kelvin (K) using the
following formulas:
Fahrenheit (F) = (9.0/5 * C) + 32
Kelvin (K) = C + 273.15
Sample Input: C = 12.3
Sample Output: F = 54.14, K = 285.45
Part 2:Write a program that prompts the user to enter a temperature in Fahrenheit (F). The program
should then convert the temperature to both Celsius (C) and Kelvin (K) using the following formulas:
Celsius (C) = (F - 32) * 5/9
Kelvin (K) = (F - 32) * 5/9 + 273.15
Sample Input: F = 54.14
Sample Output: C = 12.30, K = 285.45
Part 3:Write a program that prompts the user to enter a temperature in Kelvin (K). The program should
then convert the temperature to both Celsius (C) and Fahrenheit (F) using the following formulas:
Celsius (C) = K - 273.15
Fahrenheit (F) = (K - 273.15) * 9/5 + 32
Sample Input: K = 285.45
Sample Output: C = 12.30, F = 54.14
Problem 3: Write a program that takes two numbers, K and N, and calculates N raised to the power of K
(N^K). Finally, display the result.
Sample Input:
K=3
N=2
Sample output: 8
Problem 4: Write a program that takes two integers A and B from the user and swap their values using
a third temporary variable.
Sample Output: Before Swapping: A = 45 B = 32
After Swapping: A = 32 B = 45
BONUS: Solve the same problem, swap the values of two integers A and B but you are not allowed to
use any extra variable other than A and B.
Problem 5: Take K integers from the keyboard using a loop and print their average value on the screen.
Sample Input:
K=10
integers: 2 5 6 14 10 17 12 7 1
Sample Output: Average Value: 7.4
Problem 6:Write a program that first asks the user a number K. Then take K integers from the keyboard
using a loop and print their sum on the screen.
Sample Input: K=6
3 12 7 2 54 32
Sample Output: 110
Problem 7:
part1:Write a program to print the first K (K should be asked from the user) even numbers using a loop.
Sample Input: K = 10
Sample Output: First 10 even numbers: 2 4 6 8 10 12 14 16 18 20
part2:Write a program to print the first K (K should be asked from the user) odd numbers using a loop.
Sample Input: K = 10
Sample Output: First 10 even numbers: 1 3 5 7 9 11 13 15 17 19
Problem 8:Write a program to print the multiples of 5 less than K (K should be asked from the user)
using a loop.
Sample Input: K = 100
Sample Output: Multiples of 5 less than 100:
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95
Problem 9:Write a program to print all numbers between 1 and K in descending order (K should be
asked from the user).
Sample Input: K = 10
Sample Output: 98765432
Problem 10:Write a program exactly as we did in the class and print the table in reverse order.
Problem 11:Write a program that generates multiplication tables for a given number (N).
a) Print tables in ascending order.
b) Print tables in descending order.
c) Print tables with odd multiples only.
d) Print tables with even multiples only.
Problem 12:
Part 1:Write a program that prompts the user to enter a positive integer (N) and then prints the sum of
all the multiples of 3 or 5 that are less than N.
Sample Input:
N = 20
Sample Output:
Sum of multiples of 3 or 5 less than 20: 78
Part 2(BONUS):Modify the program to also allow the user to input the two numbers (M and N) to find
the sum of multiples of M or N that are less than K.
Sample Input:
M = 3, N = 5, K = 100
Sample Output:
Sum of multiples of 3 or 5 less than 100: 2418
O===O
\O/
|
/\
Happy Coding :)
Good luck