0% found this document useful (0 votes)
2 views5 pages

Functions

The document outlines a series of programming tasks that involve defining various functions in C/C++. Each task includes specific functions for mathematical operations, geometric calculations, number checks (like prime, palindrome, special, spy, etc.), and pattern printing, with instructions on how to implement them in the main function.

Uploaded by

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

Functions

The document outlines a series of programming tasks that involve defining various functions in C/C++. Each task includes specific functions for mathematical operations, geometric calculations, number checks (like prime, palindrome, special, spy, etc.), and pattern printing, with instructions on how to implement them in the main function.

Uploaded by

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

FUNCTIONS

1. Define functions.
void add (int a, int b): to find and print sum of two numbers.
void product (int a, int b): to find and print product of two numbers.
Now in main(): input two numbers, find their sum and product using above defined functions.
2. Define functions.
void area(int l ,int b): to find and print area of rectangle
void perimeter (int l, Int b): to find and print perimeter of rectangle.
Now in main(): input length and breadth, find area and product using above defined functions.
3. Define functions.
void area (int r): to find and print area of circle
void circum(int r): to find and print circumference of circle
Now in main(): input radius of a circle, find its area and circumference using above functions.
4. Define functions.
void checkprime (int x): to check and print is x a prime number or not?
Now in main(): input a number and check is it prime or not using above functions.
5. Define functions.
void volume (int l, int b,int h): to calculate and print volume.
void diagonal(int l,int b,int h): to calculate and print diagonal.
Now in main(): input length, breadth, height. Calculate and print its volume using above functions.
6. Define functions.
void checkPalindrome (int x): to check and print is x a palindrome number or not.
Now in main (): input a number and check is it palindrome or not using above function.
7. Define functions.
void checkspecial (int n): to check n is a special number or not?
(Special number : sum of factorial of digits = number)
Now in main(): input a number and check it is special number or not using above functions.
8. Define functions.
void checkSpy (int n): to check n is a spy number or not ?
(Spy number: when sum of digits = product of digits)
Now in main(): input a number and check is it a spy number or not using above functions.
9. Define functions.
int area (int I, int b): to find and return area of a rectangle.
int perimeter (int l, int b): to find and return perimeter of a rectangle.
Now in main(): input length, breadth from user. Find area and perimeter using above functions also print
their difference.
10. Define functions.
int sumFactor (int n) : to find and return sum of factors of n.(Perfect number: sum of factors = number)
Now in main (): to find its sum of factors using above functions and check is it perfect number or not.
11. Define functions:
int sumDigit (int a):to find and return sum of digits of n.(Niven number: number divisible by sum of
digits)
Now in main: input a number and find its sum of digits using above functions and check is it Niven
number or not?
12. Define function:
int countFactor (int n): to count and return number of factors of n.
Now in main(): print all two-digit prime numbers using above function.
13. Define function.
int countFactor (int n): to count and return number of factors of n.(Twin prime: A pair of prime numbers
with difference of two)
Now in main (): input two numbers and check they are twin prime or not ?To count factor use above
defined function.
14. Define functions.
int countFactor (int n): to count and return number of factors of n.
int reverse (int n): to find and return reverse of n.(Palprime number: when a number is prime as well as
palindrome)
Now in main() : input a number from user and check is it palprime or not?
15. Define functions.
int countDigit (int n): to count and return number of digits of n.(Automorphic number: When square
number contains the original number itself as its last digits)
Now in main (): input a number from user and check is it automorphic number or not? To count number
of digits using above functions.
16. Define overloaded functions area ().
void area (int r): to find and print area of a circle.
void area (int l, int b): to find and print area of rectangle.
Now in main(): input r, l, b find area of circle and rectangle.
17. Define overloaded function series ()
void series (int n): to print
1 4 9.....n terms
void series (int x, int n): to print table of x upto n terms.
Now in main (): use above functions to get the result.
18. Define overloaded function sumseries ( ):
void sumseries (int n): to find and print sum of
s = 1+2+3…..n terms
void sumseries (int x, int n): to find and print sum of
s = x+x2+x3+…n terms
Now in main ( ): print the above series.
19. Define overloaded function pattern ( ):
void pattern (int n):
when n=4
1 2 3 4 5
2 3 4 5
3 4 5
4
void pattern ( ):
1 2 3 4
5 6 7
8 9
10
20. Define overloaded function :
void pattern( char ch, int n):
when ch=# & n=4
1 2 3 4
# # #
1 2
#
void pattern(int n):
when n=3
* * *
* *
*
Use it main( )
21. Define overloaded function:
double perform (double r, double h): to calculate and return the value of CSA of cone
CSA= π rl
l= √❑
void perform (int r, int c): Use nested loop to generate the following format
when r=3, c=5,
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
void perform (int m, int n, char ch): to print the quotient of the division of m and n if ch is Q else print
the remainder of the division of m and n if ch is R.
22. Define overloaded function :
void print( ): to print the following format
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print (int n): to check whether the number is a lead number or not.
(Lead number – sum of even digits = sum of odd digits)
23. define overloaded function :
void number (int num, int d): to count and display the frequency of a digit in a number.
eg: num = 2565685
d=5
frequency of digit 5 = 3
void number (int n): to find and display the sum of even digits of a number.
Write main ( ).
24. Define overloaded function:
void sumseries (int n, double x): to find and display the sum of the given series
x x x
s= − + ….n
1 2 3
void sumseries ( ):to find and display the sum of given series.
s = 1+(1*2)+(1*2*3)+……..+(1*2*….*20)
25. Define overloaded function:
void display ( ): to print using method loop
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
void display (int n): to print square root of each digit of given number
eg: n = 43
o/p :
1.732050808
2.0
26. Define function:
Boolean isPerfectsquare (int n): to check given number is perfect square or not ?
Now in main ( ): Input ten values from users find the sum of perfect square using above function.
27. Define overloaded function:
double volume (double r): with radius ( r ) as argument , returns the volume of sphere using the formula
4
∗22
V= 3
∗r 3
7
double volume (double h, double r): with height(h), radius (r) as arguments, and returns volume of
cylinder using
22 2
V = ∗r ∗h
7
double volume (double l, double b, double h): with length(l), breadth(b) sand height(h) as arguments,
returns the volume of a cuboids using
V = l*b*h
28. WAP to consider the following prototype :
boolean even (int n): which checks whether the given number is even or not.
Now in main( ): input a number and check and print.
29. Create a method with the following prototype :
int fact (int n): which finds the factorial of a number and returns it.
Now in main ( ): call function and print value.
30. WAP to create a method with the following prototype:
int reverse (int n): which reverses the given number.
Now in main ( ): input a number and check whether reverse number is same as original number.Use
above functions.
31. Define overloaded function :
1 2 3
double series (int n): + + … .n terms
2 3 4
1 3 5
x x x
double series (int x, int n): + + … . n terms
2 4 6
Now in main( ): input values and call the above functions.
32. Define overloaded function:
void pattern (int n): which prints the following pattern
when n=5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
void pattern (char ch, int m, int n): which prints the following pattern
when ch=@
m=4
n=3
@@@@
@@@@

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