0% found this document useful (0 votes)
4 views6 pages

Function Related Problems: (Total 20 Questions)

The document outlines a series of 20 function-related problems, each with varying levels of difficulty, designed for programming practice. Problems include tasks such as printing messages, calculating sums, swapping numbers, finding prime numbers, and performing operations on matrices. Each problem is accompanied by sample inputs and outputs to illustrate expected results.

Uploaded by

Tausif Ahmed
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)
4 views6 pages

Function Related Problems: (Total 20 Questions)

The document outlines a series of 20 function-related problems, each with varying levels of difficulty, designed for programming practice. Problems include tasks such as printing messages, calculating sums, swapping numbers, finding prime numbers, and performing operations on matrices. Each problem is accompanied by sample inputs and outputs to illustrate expected results.

Uploaded by

Tausif Ahmed
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/ 6

Function Related Problems

(Total 20 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 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

4. 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

5. 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

Documentation by Samiha Samrose, Lecturer, CSE Dept, UIU, Dhaka, Bangladesh.


6. 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

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

8. 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

9. 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

10. 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

Documentation by Samiha Samrose, Lecturer, CSE Dept, UIU, Dhaka, Bangladesh.


11. 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

12. 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

13. 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

14. 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

Documentation by Samiha Samrose, Lecturer, CSE Dept, UIU, Dhaka, Bangladesh.


15. 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

16. 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

17. 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

Documentation by Samiha Samrose, Lecturer, CSE Dept, UIU, Dhaka, Bangladesh.


18. 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

19. 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

Documentation by Samiha Samrose, Lecturer, CSE Dept, UIU, Dhaka, Bangladesh.


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

20. 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!

Documentation by Samiha Samrose, Lecturer, CSE Dept, UIU, Dhaka, Bangladesh.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy