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

Functions Exercises

The document outlines a series of C++ and C programming exercises focused on functions, including creating a calculator menu, calculating Fibonacci numbers, and performing various mathematical operations. It also includes tasks such as sorting values, checking for prime numbers, and implementing recursion. Each exercise emphasizes the use of functions to solve specific problems.

Uploaded by

amob8492
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)
2 views2 pages

Functions Exercises

The document outlines a series of C++ and C programming exercises focused on functions, including creating a calculator menu, calculating Fibonacci numbers, and performing various mathematical operations. It also includes tasks such as sorting values, checking for prime numbers, and implementing recursion. Each exercise emphasizes the use of functions to solve specific problems.

Uploaded by

amob8492
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

C++ Exercises

Functions Miss:Elham Shammar

1. Write a C++ program that will display the calculator menu.


The program will prompt the user to choose the operation choice (from 1 to 5). Then it asks the
user to input two integer vales for the calculation. See the sample below. (each operation will be
in a separate function).

MENU
1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus
Enter your choice: 1
Enter your two numbers: 12 15
Result: 27

Continue? y

The program also asks the user to decide whether he/she wants to continue the operation. If
he/she input ‘y’, the program will prompt the user to choose the operation gain. Otherwise, the
program will terminate.

2. Write a function to calculate Fubanaci numbers Xn, Xn, n=1,1,2,3,5,8 …,1000

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

The next number is found by adding up the two numbers before it:

• the 2 is found by adding the two numbers before it (1+1),


• the 3 is found by adding the two numbers before it (1+2),
• the 5 is (2+3),
• and so on!

3. Write functions to find this operation


• Read n number and find n!.(factorial of n)
• Read n number and find sum(n)
• Read n ,m numbers and found pow(n,m).

1
4. Write a function to calculate the area of a triangle with sides a,b and c.

5. Write a C++ program (using function overloaded) to sort 10 integer values, or 10 long

values, or 10 double values.

6. Write a program in C to swap two numbers using function.

7. Write a program in C to check a given number is even or odd using the function

8. Write a program in C to find the sum of the series 1!/1+2!/2+3!/3+4!/4+5!/5 using the

function.

9. Write a program in C to convert decimal number to binary number using the function.

10. Write a C++function to print a number in reverse for example input: 124567 output: 765421

11. Write a program in C to check whether a number is a prime number or not using the

function.

12. Write a program in C to get the largest element of an array using the function.

13. Write C++ program that implement the power function using recursion function.

14. Write a recursive function to calculate Fibonacci numbers Xn, n=1,1,2,3,5,8 …,1000

You might also like