0% found this document useful (0 votes)
10 views3 pages

Funtion Loop

The document contains questions about writing programs that use functions and loops to perform tasks like creating functions with variable arguments, returning multiple values from functions, creating recursive functions, checking for palindromes, and calculating sums and factorials.

Uploaded by

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

Funtion Loop

The document contains questions about writing programs that use functions and loops to perform tasks like creating functions with variable arguments, returning multiple values from functions, creating recursive functions, checking for palindromes, and calculating sums and factorials.

Uploaded by

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

PFP – Function+Loop

Q1 (2.5 marks). Write a program that performs the following tasks:


1. Create a function with variable length of arguments

2. Return multiple values from a function

Q2 (2.5 marks). Write a program to accept 2 integer numbers m and n, then:


1. Create a function with default argument
2. Create an inner function to calculate the addition in the following way
 Create an outer function that will accept two parameters, a and b
 Create an inner function inside an outer function that will calculate the addition of a and b
 At last, an outer function will add 5 into addition and return it

Q3 (2.5 marks). Write a program that performs the following tasks:


1. Create a recursive function
Write a program to create a recursive function to calculate the sum of numbers from 0 to 10.
A recursive function is a function that calls itself, again and again.

2. Assign a different name to function and call it through the new name

Output:
Q4 (2.5 marks). Write a program that performs the following tasks:
1. Check Palindrome Number
A palindrome number is a number that is same after reverse. For example 545, is the palindrome
numbers

2. Find the largest item from a given list

Write a program that performs the following tasks:


3. Input an integer number n, where n > 5 (If n≤ 5 then prompt a user to re-enter). Then calculate
4. S1 = 1 + 2 + 3 + ... + n.
5. S2 = n!
6. S3 =1+ + +...+ .
7. Re-input n. Check whether n is a prime number or not.

Write a program to accept 2 integer numbers m and n, then:


3. Display all common prime dividers of them.
4. Find the greatest common divider (GCD) of them.
5. Find the least common multiple (LCM) of them.

Write a program that performs the following tasks:


3. Input an integer number n (check input validation), then
4. Display n in binary number format.
5. Re-input n (not check input validation). Calculate the sum of all digits of n.
6. Find the number m, which is the reverse of n.

Write a program
to accept 2 integer numbers m and n, where m < n then
Display all palindrom numbers in the interval [m.n]. (A palindromic number or numeral
palindrome is a number that remains the same when its digits are reversed, e.g. 16461)

You might also like