Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views8 pages

Practice Problems

The document contains a series of programming tasks and their expected outputs, covering basic operations such as printing messages, performing arithmetic calculations, and manipulating strings and arrays. Each task includes specific inputs and the corresponding outputs, demonstrating fundamental programming concepts. The tasks range from simple printing to more complex operations like calculating GCD, LCM, and sorting arrays.

Uploaded by

t.m.labonnya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Practice Problems

The document contains a series of programming tasks and their expected outputs, covering basic operations such as printing messages, performing arithmetic calculations, and manipulating strings and arrays. Each task includes specific inputs and the corresponding outputs, demonstrating fundamental programming concepts. The tasks range from simple printing to more complex operations like calculating GCD, LCM, and sorting arrays.

Uploaded by

t.m.labonnya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.​ Print "Hello, World!

"​
Output:​
Hello, World!​

2.​ Print your name and university​


Output:​
Name: Sarah Ahmed​
University: ULAB​

3.​ Print the sum of two fixed numbers​


Output:​
5 + 3 = 8​

4.​ Take two integers as input and print their sum​


Input: 4 7​
Output: Sum: 11​

5.​ Take two numbers as input and print their difference​


Input: 10 3​
Output: Difference: 7​

6.​ Multiply two integers taken from the user​


Input: 5 6​
Output: Product: 30​

7.​ Divide two integers and print the quotient​


Input: 20 4​
Output: Quotient: 5​

8.​ Calculate the remainder of two integers​


Input: 22 5​
Output: Remainder: 2​

9.​ Swap two numbers using a temporary variable​


Input: a = 10, b = 20​
Output: a = 20, b = 10​

10.​Swap two numbers without using a temporary variable​


Input: a = 3, b = 7​
Output: a = 7, b = 3​

11.​Check if a number is even or odd​


Input: 9​
Output: Odd​

12.​Check if a number is positive, negative, or zero​


Input: -5​
Output: Negative​

13.​Find the maximum of two numbers​


Input: 13 29​
Output: Maximum: 29​
14.​Find the maximum of three numbers​
Input: 3 8 5​
Output: Maximum: 8​

15.​Check if a number is divisible by 3 and 5​


Input: 30​
Output: Divisible by both 3 and 5​

16.​Check if a character is a vowel or consonant​


Input: e​
Output: Vowel​

17.​Check if a year is a leap year​


Input: 2024​
Output: Leap Year​

18.​Calculate the area of a rectangle​


Input: Length = 5, Width = 3​
Output: Area = 15​

19.​Calculate the area of a circle​


Input: Radius = 4​
Output: Area = 50.27​

20.​Convert temperature from Celsius to Fahrenheit​


Input: Celsius = 0​
Output: Fahrenheit = 32​
21.​Print numbers from 1 to 10 using a loop​
Output: 1 2 3 4 5 6 7 8 9 10​

22.​Print even numbers from 1 to 100​


Output: 2 4 6 ... 100​

23.​Print the sum of numbers from 1 to N​


Input: 5​
Output: Sum = 15​

24.​Print the multiplication table of a number​


Input: 5​
Output:​
5 x 1 = 5​
5 x 2 = 10​
...​
5 x 10 = 50​

25.​Calculate the factorial of a number​


Input: 5​
Output: Factorial = 120​

26.​Print the first N Fibonacci numbers​


Input: 7​
Output: 0 1 1 2 3 5 8​
27.​Count digits in a number​
Input: 786​
Output: Digits: 3​

28.​Reverse the digits of a number​


Input: 123​
Output: 321​

29.​Check if a number is a palindrome​


Input: 121​
Output: Palindrome​

30.​Check if a number is a prime​


Input: 7​
Output: Prime​

31.​Print all prime numbers between 1 and 100​


Output: 2 3 5 7 11 ... 97​

32.​Find the GCD of two numbers​


Input: 12 18​
Output: GCD = 6​

33.​Find the LCM of two numbers​


Input: 4 6​
Output: LCM = 12​
34.​Create a simple calculator using switch statement​
Input: 8 + 3​
Output: Result = 11​

35.​Count the number of vowels in a string​


Input: hello​
Output: Vowels = 2​

36.​Reverse a string​
Input: cat​
Output: tac​

37.​Check if a string is a palindrome​


Input: madam​
Output: Palindrome​

38.​Print ASCII value of a character​


Input: A​
Output: 65​

39.​Convert a lowercase letter to uppercase​


Input: c​
Output: C​

40.​Sort three numbers in ascending order​


Input: 9 2 5​
Output: 2 5 9​

41.​Use a function to find the square of a number​


Input: 4​
Output: Square = 16​

42.​Use a function to find the maximum of two numbers​


Input: 10 25​
Output: Max = 25​

43.​Write a function to check if a number is prime​


Input: 17​
Output: Prime​

44.​Write a recursive function to calculate factorial​


Input: 5​
Output: 120​

45.​Write a recursive function to calculate power (x^y)​


Input: 2 3​
Output: 8​

46.​Take an array of 5 elements and print them​


Input: 1 2 3 4 5​
Output: 1 2 3 4 5​
47.​Find the largest element in an array​
Input: 3 7 2 9 5​
Output: Max = 9​

48.​Find the sum of elements in an array​


Input: 1 2 3 4 5​
Output: Sum = 15​

49.​Count the frequency of an element in an array​


Input: 2 3 2 4 2, Find: 2​
Output: Frequency = 3​

50.​Sort an array using bubble sort​


Input: 5 2 9 1 5​
Output: 1 2 5 5 9​

You might also like