You are on page 1of 5

TASK 1

Algorithm
1. Start
2. Declare int bas, p and ans
3. Ask the user to enter the base value and store it in bas
4. Ask the user to enter the power value and store it in p
5. Call the function calPow(bas, p)
6. Print the result
7. End

Pseudo code

Start
Declare int bas, p and ans
Ask the user to enter the base value and store it in bas
Ask the user to enter the power value and store it in p
IF(p != 0) calPow(bas, p - 1) ELSE return 1 ans = calPow(bas, p)
Print the result .
End

C++ CODE
#include <iostream>
using namespace std;
int calPow( int bas, int p) //using power function
{
if (p != 0) //appying if else conditions
return (bas*calPow(bas, p - 1)); //calling power function
else //another condition
return 1;
}
int main() //main function
{
int bas, p, ans; //initializing

cout << "Please put the base value: "; //output


cin >> bas; //enter the base value
cout << "Please put the exponential power: "; //output
cin >> p; // enter the power value

ans = calPow(bas, p); // calling function


cout << bas << " raised to the power " << p << " is " << ans<<endl;
//printing of the result that we want
return 0;
system ("pause");
}

https://replit.com/@MohazQ/up-task-one#main.cpp

TASK 2
ALGORITHM:
1. Begin
2. Initialize two variables x and i.
3. Read the value of x from user.
4. Create a function called fibo which takes x as argument.
5. In the function, check if x is equal to 1 or 0, if yes then return x.
6. If x is not equal to 1 or 0 then return fibo(x-1) + fibo(x-2).
7. Print the Fibonacci Series of x numbers by using for loop starting from 0 to x.
8. Call the fibo function inside the for loop.
9. Display the output.
10. End.

PSEUDOCODE:
START
// Initialize two variables x and i
int x,i // Read the value of x from user READ x
// Create a function called fibo which takes x as argument int fibo(int x)
IF (x == 1 OR x == 0)
RETURN x
ELSE RETURN fibo(x-1) + fibo(x-2)
// Print the Fibonacci series of x numbers FOR (i=0; i<x; i++)
PRINT fibo(i) // Display the output PRINT "Fibonacci Series of " x " numbers is: "
END

C++ CODE
//programm of generation of fibonacci series from recursive function
#include <iostream>
using namespace std;
int fibo(int x) //fibonacci series
{
//using if else conditions
if ((x == 1) || (x == 0))
{
return(x); //returning of the value
}
else {
return(fibo(x - 1) + fibo(x - 2)); //calling of function
}
}
int main() ///main function
{
int x, i; //initialising
cout << " any number that you want to make the fibonacci series: ";
//output
cin >> x; //enter any number
cout << "Fibonnaci Series of " << x << " numbers is: ";
//loop to print fibonacci series
for (i = 0; i < x; i++)
{
cout << " ";
cout << fibo(i);
}
return 0;
system("pause");
}
https://replit.com/@MohazQ/up-task-2#main.cpp

You might also like