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. = P × R × 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.
Permutation(n, r) = n P r = 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.
Permutation(n, r) = n P r = n ! ( n r ) !


Q11: Write a program to define a function that returns the permutation of n and r.
Permutation(n, r) = n P r = n ! ( n r ) ! = n ( n 1 ) ( n 2 ) . . . r   terms


Q12: Write a program to define a function that returns the combination of n and r.
Combination(n, r) = n C r = 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.
Combination(n, r) = n C r = n ! ( n r ) !   r !


Q14: Write a program to define a function that returns the combinations of n and r.
Combination(n, r) = n C r = n ! ( n r ) !   r ! = n ( n 1 ) ( n 2 ) . . . r   terms 1 × 2 × 3. . . r   (r terms) = i   =   0 r     1 n i i + 1


Check Solution