Skip to content

Latest commit

 

History

History
109 lines (74 loc) · 3.02 KB

Practice_code4.md

File metadata and controls

109 lines (74 loc) · 3.02 KB
title subtitle
Practice Functions
Practice Code 4

This Notebook Contains practice question for the note on Functions.

Try working online at:
Coding Ground - Tutorials Point
Online Compiler and Debugger


Q1: Write a program to define a function multiply which get two parameters and returns the product of them.


Q2: Write a program to create a function that gets sides of a rectangle and return its perimeter and area.


Q3: Write a program to create a function that gets a number n and a value s and prints the value n times as output.

Sample 1:
I/P:
10
Hello

O/P:
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello


>**Sample 2:** I/P: 5
1

O/P: 1
1
1
1 1

Q4: Write a program to define a function to determine simple interest for given values of Principal, Rate p.a. and duration in years.
Simple Interest, S.I. = $\dfrac{P \times R \times T}{100}$


Q5: Write a program to get a number n and and print the prime numbers from 1 to n. Use function to check if a number is prime or not.


Q6: Write a program to define a function to return factorial of the number passed in it (use recursion).


Q7: Write a program to define a function to return factorial of the number passed in it (without recursion).


Q8: Write a program to define a function that gets a year as input and print if it is a leap year or not.

Condition: A year is leap if it is either divisible 4 or 400 and not 100.


Q9: Write a program to define a function that returns the permutation of n and r.
$\text{Permutation(n, r)} = {}^nP_r = \dfrac{n!}{(n-r)!}$


Q10: Write a program to define a function that returns the permutation of n and r. Use recursion to compute the factorials.
$\text{Permutation(n, r)} = {}^nP_r = \dfrac{n!}{(n-r)!}$


Q11: Write a program to define a function that returns the permutation of n and r.
$\text{Permutation(n, r)} = {}^nP_r$ = $\dfrac{n!}{(n-r)!} = n(n-1)(n-2)...r ~\text{terms}$


Q12: Write a program to define a function that returns the combination of n and r.
$\text{Combination(n, r)} = {}^nC_r = \dfrac{n!}{(n-r)!~r!}$


Q13: Write a program to define a function that returns the combinations of n and r. Use recursion to compute the factorials.
$\text{Combination(n, r)} = {}^nC_r = \dfrac{n!}{(n-r)!~r!}$


Q14: Write a program to define a function that returns the combinations of n and r.
$\text{Combination(n, r)} = {}^nC_r = \dfrac{n!}{(n-r)!~r!} = \dfrac{n(n-1)(n-2)...r ~\text{terms}}{1 \times 2 \times 3... r ~\text{(r terms)}} = \displaystyle \prod_{i ~= ~0}^{r ~-~1} \dfrac{n-i}{i+1}$


Check Solution