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

09 Function

The document outlines 27 function-related programming problems, each with a specific problem statement and difficulty level. The problems range from basic tasks like printing messages and determining even or odd numbers to more complex tasks such as calculating standard deviation and converting numbers to different bases. Sample inputs and outputs are provided for each problem to illustrate expected functionality.

Uploaded by

ab.taufiq786
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)
9 views8 pages

09 Function

The document outlines 27 function-related programming problems, each with a specific problem statement and difficulty level. The problems range from basic tasks like printing messages and determining even or odd numbers to more complex tasks such as calculating standard deviation and converting numbers to different bases. Sample inputs and outputs are provided for each problem to illustrate expected functionality.

Uploaded by

ab.taufiq786
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

Function Related Problems

(Total 27 questions)

SL Problem statement Difficulty


levels
1. Function to print a custom message. *

Sample input Sample output


This is a function

2. Function to print an input character value. *

Sample input Sample output


3 Value received from main: 3
A Value received from main: A

3. Function to determine if a number is even or odd. *

Sample input Sample output


3 odd
8 even

4. Function to determine if a number is positive, negative or zero. *

Sample input Sample output


3 positive
-5 negative
0 zero

5. Function that takes two numbers as input and determines if the first number is greater than, *
equal to or less than the second number.

Sample input Sample output


54 5 is greater than 4
26 2 is less than 6
88 8 is equal to 8
6. Function to calculate the sum of n numbers coming from the console. *

Sample input Sample output


80 33 27 Sum In Function: 140
Sum In Main: 140
100 -100 Sum In Function: 0
Sum In Main: 0

7. Function to calculate the sum of n numbers coming from the console and stored in an array. *

Sample input Sample output


3 Sum In Function: 140
80 33 27 Sum In Main: 140
2 Sum In Function: 0
100 -100 Sum In Main: 0

8. Function that takes an array of n integer numbers as input and prints them in reverse order. *

Sample input Sample output


3 284
482
7 9 21 43 8 34 12 5
5 12 34 8 43 21 9

9. Function to calculate the factorial of a number. *

Sample input Sample output


3 6
5 120

10. Function to take two positive numbers x and y as input and calculate x to the power y. *

Sample input Sample output


34 3 to the power 4 is 81
10 3 10 to the power 3 is 1000
11. Function to take a string as input and find its length. *

Sample input Sample output


hello world 11
I love my country 17

12. Function to swap two numbers. *


(Restriction: Pass by value)

Sample input Sample output


10 20 Value in func: 20 10
Value in main: 10 20

13. Function to swap two numbers. **


(Restriction: Pass by reference)

Sample input Sample output


10 20 Value in func: 20 10
Value in main: 20 10

14. Function to determine only even numbers in an array of input integers. *

Sample input Sample output


24 77 117 -512 1024 24 -512 1024
45 33 0 256 0 256

15. Function that finds and returns the minimum value in an array. **

Sample input Sample output


157 -28 -37 26 10 Minimum Value: -37
12 45 1 10 5 3 22 Minimum Value: 1

16. Function that multiplies the array elements by 2 and returns the array. *
Sample input Sample output
157 -28 -37 26 10 314 -56 -74 52 20
12 45 1 10 5 3 22 24 90 2 20 10 6 44

17. Function to sort and return an input array in ascending order. **

Sample input Sample output


10 22 -5 117 0 -5 0 10 22 117

18. Function “IsPrime()” to determine whether a number is prime or not. **

Sample input Sample output


1 Not prime
2 Prime
11 Prime
39 Not prime
101 Prime

19. Function “GeneratePrime()” to compute the prime numbers less than N, where N is an input ***
integer. GeneratePrime() uses IsPrime() to check whether a number is prime or not.

Sample input Sample output


5 Prime less than 5: 2, 3
10 Prime less than 10: 2, 3, 5, 7
40 Prime less than 17: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37

20. Function “GenNthPrime()” to compute the Nth prime number, where N is an integer input. ***

Sample input Sample output


5 5th Prime: 11
10 10th Prime: 29
40 40th Prime: 173
21. Implement the following functions and calculate standard deviation of an array whose values ***
come from the terminal-
TakeInput()
CalcMean(array, num_of_elem)
Calc_Std_deviation(array, num_of_elem)

Formula:

Sample input Sample output


4 5 5 4 4 2 2 6 1.32
600 470 170 430 300 147.32

22. Function find_substr( ) that takes two string arrays (a, b) as parameters, returns 1 if string b **
is found anywhere in string a, or returns –1 if no match is found.

(Assuming, strlen(a)>strlen(b))

Sample input (a, b) Sample output


madam adam 1
telescope less 0
101010 101 1

23. Function find_substr( ) that takes two string arrays (a, b) as parameters, uses function ***
str_length() to determine the lengths of the strings, and then looks for the smaller string
anywhere in the bigger string. It returns 1 if the substring is found, or returns –1 if no match
is found.

[Restriction: str_length() cannot uses built-in strlen() function]

Sample input (a, b) Sample output


madam adam 1
telescope less 0
101010 101 1
24. Program that continuously takes two positive integers as inputs and uses two functions to **
find their GCD (greatest common divisor) and LCM (least common multiple). Both functions
take parameters and returns desired values.

[Hint: Use infinite loop to process inputs]

Sample input Sample output


5 7 GCD: 1
LCM: 35
12 12 GCD: 12
LCM: 12
12 32 GCD: 4
LCM: 96

25. Program that implements function to perform operations on a 3X5 matrix: ***

InputMatrix()
ShowMatrix()
ScalarMultiply()

Sample input Sample output


7 16 55 13 12 Original:
12 10 52 0 7 7 16 55 13 12
-2 1 2 4 9 12 10 52 0 7
-2 1 2 4 9
2
Multiplied by 2:
14 32 110 26 24
24 20 104 0 14
-4 2 4 8 18
7 16 55 13 12 Original:
12 10 52 0 7 7 16 55 13 12
-2 1 2 4 9 12 10 52 0 7
-2 1 2 4 9
-1
Multiplied by -1:
-14 -32 -110 -26 -24
-24 -20 -104 0 -14
4 -2 -4 -8 -18
26. Program that implements function to perform operations on a MXN matrix: ****

InputMatrix()
ShowMatrix()
ScalarMultiply()

Sample input Sample output


2 2 Original:
7 16
7 16 12 10
12 10
Multiplied by 2:
2 14 32
24 20

3 5 Original:
7 16 55 13 12
7 16 55 13 12 12 10 52 0 7
12 10 52 0 7 -2 1 2 4 9
-2 1 2 4 9
Multiplied by -1:
-1 -14 -32 -110 -26 -24
-24 -20 -104 0 -14
4 -2 -4 -8 -18

27. Program to convert a positive integer to another base using the following functions- ****

I. Get_Number_And_Base () : Takes number to be converted (N) and base value (B)


from user. Base must be between 2 and 16.

II. Convert_Number () : Does the conversion

III. Show_Converted_Number() : Displays the converted value.

Sample input(N,B) Sample output


100 8 144
512 16 200
512 0 Base not within proper range!

You might also like