0% found this document useful (0 votes)
20 views1 page

PL - 3 Functions

The document outlines a practical list of user-defined functions in programming. It includes tasks such as defining functions for checking prime numbers, divisibility, calculating factorials, powers, reversing integers, and finding sums of digits, LCM, and HCF. Additionally, it provides instructions for creating patterns and calculating various mathematical series using these functions.

Uploaded by

bludoggo2008
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)
20 views1 page

PL - 3 Functions

The document outlines a practical list of user-defined functions in programming. It includes tasks such as defining functions for checking prime numbers, divisibility, calculating factorials, powers, reversing integers, and finding sums of digits, LCM, and HCF. Additionally, it provides instructions for creating patterns and calculating various mathematical series using these functions.

Uploaded by

bludoggo2008
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

PRACTICAL LIST – 3

User – Defined Functions


1 Define a function Isprime( ) that returns 1 if the value passed to its parameter is a prime integer otherwise it returns 0.
Use this function in the program to display all prime numbers between 1 and 100.
2 Define a function Div2( ) that returns 1 if n is divisible by 2 otherwise it returns 0, and Div3( ) that returns 1 if n is
divisible by 3 otherwise it returns 0.
Use these functions in the program to check whether a number NUM is divisible by both 2 and 3 or not.
3 Define a function Factorial ( ) that returns the factorial of the integer passed to its parameter. Use this function in the
program to display the sum of the following series:
1! + 2! + 3! + 4! +……………... upto N terms (where value of N is entered by the user)
4 Define a function Power ( ) that returns the result of x y by passing x and y as parameters . (Don’t use exponent
operator or built-in function.
Use this function in the program to enter values of T and N and display the sum of the following series:
T + T 2 + T 3 + T 4 +……………...upto N terms
5 Define a function Reverse ( ), that returns the reverse of the integer passed to its parameter. Use this function in the
program to display whether an integer entered by the user is a Palindrome or not.
Note: A palindrome integer is a number which is same as its reverse, example: 1221, 13531, 24342 etc.
6 Define a function Sum( ) that returns the sum of digits of an integer passed to its parameter. For example if the
integer passed is 2134, then the function should return 10 (i.e. the result of 2+1+3+4). Call this function and display
sum of digits of three different integers entered by the user.
7 Define a function LCM( ) , that returns the LCM of the two integers passed to its parameter. Use this function in a
program to enter 3 integers and display their LCM.
8 Define a function HCF( ), that returns the HCF of the two integers passed to its parameter. Use this function in a
program to enter 3 integers and display their HCF.
9 Define functions to make following patterns, for N number of lines (value of N to be passed to the function
parameter):
123 1 111
12 12 22
1 123 3
Call these functions in the main program and find results with the help of appropriate menu driven options.
10 Define functions to find sum of following series:
(i) X+X 2 + X 3 +............ + X N (use int N and float X as parameters)
U2 U3 UN
(ii) U+ 2! + 3!
+...……… + N!
(use int N and float U as parameters)

(iii) X+2*X+3*X+... +N*X (use int N and float X as parameters)


2! 3! 4! N!
(iv) 1 - U2 + U3 - U4 ...……… + UN (use int N and float U as parameters)

Call these functions in the main program and find results sum of various series with the help of appropriate menu
driven options.

You might also like