0% found this document useful (0 votes)
75 views2 pages

Pract List 3

The document provides instructions for students to create 11 programs using functions in C++. It instructs students to define various functions to calculate things like prime numbers, factorials, palindromes, patterns, and series. It also provides formatting instructions for commenting programs with assignment details.

Uploaded by

Lakshay Bans
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)
75 views2 pages

Pract List 3

The document provides instructions for students to create 11 programs using functions in C++. It instructs students to define various functions to calculate things like prime numbers, factorials, palindromes, patterns, and series. It also provides formatting instructions for commenting programs with assignment details.

Uploaded by

Lakshay Bans
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/ 2

Delhi Public School, R.K.

Puram Computer Science

1. Define a function ​int ​Isprime(int) 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 ​int Div2(int n) that returns 1 if n is divisible by 2 otherwise it returns 0, and ​int
Div3(int n) 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 ​long Factorial (int) 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 l​ong Power (int x, int y) t​hat returns the result of ​xy​​ . ​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 ​long Reverse (long)​, 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 ​int Sum (int) 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 in main() and display sum of digits of three different integers entered by
the user.

7. Define a function ​int LCM (int, int)​, 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 ​int HCF (int, int)​, 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):
(i) (ii) (iii)

1 2 3 4 1 1 1 1 1
1 2 3 1 2 2 2 2
1 2 1 2 3 3 3
1 1 2 3 4 4

Call these functions in the main() 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)

Practical List 3:Functions in C++ CScXI/2016_2017/MD/9 #1


Delhi Public School, R.K.Puram Computer Science

(ii) U+U​2​/2!+U​3​/3!+... U​N​/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)
Call these functions in the main() and find results sum of various series with the help of appropriate
menu driven options.

11. Define a function ​void Square( int N) which takes the length of a square (less than 15) as its
parameter and displays a square of N number of stars. For example, if value of N is passed as 3 then
the following square should be displayed:
* * *
* * *
* * *

Call the above function with appropriate parameter(s) in main() to display the following pattern:
*
* * *
* * *
* * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
General Instructions:
i. Type the programs mentioned above during the Lab Periods
ii. Type in the assignment details on top of each of your program as comment lines in the following
format:
/*
Practical List : 3
Program No : 10
Developed By : Abdul Sriprakash, Gareema Peter, John Chandrashekhar
Date : 29-October-2015
*/
iii. On successful compilation and execution, copy and paste the sample output at the bottom of the
program as comment lines.
iv. Take out a hardcopy of the program from the printer and get it signed from the respective computer
teacher. Paste this printout in the practical file and get the index entry also signed.

Practical List 3:Functions in C++ CScXI/2016_2017/MD/9 #2

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