# Make a simple calculator. Display and perform the following functionality.

# Scientific Calculator

## 1. Press 1 for Subtraction

2. Press 2 for average of 3 numbers

3. Press 3 for cube of number

4. Press 4 to print the factorial of number

5. Press 5 to print the Fibonacci series

6. Press 6 for square of number

**code :**

#include <iostream>

#include<cmath>

using namespace std;

int main()

{

char choice;

cout << "Press 1 for Subtraction"<<endl;

cout << "Press 2 for average of 3 numbers"<<endl;

cout << "Press 3 for cube of number"<<endl;

cout << "Press 4 to print the factorial of number"<<endl;

cout << "Press 5 to print the Fibonacci series"<<endl;

cout << "Press 6 for square of number"<<endl;

cin >> choice;

switch(choice) {

case'1':{

float n1, n2;

cout<<"Enter two numbers"<<endl;

cin >>n1 >> n2;

cout <<"substraction of two numbers="<< n1-n2<<endl<<endl;

break;

}

case'2':{

float n3,n4,n5,Add,Average;

cout<<"Enter three number for average"<<endl;

cin >> n3 >> n4 >> n5;

Add=n3+n4+n5;

cout<<"Average of three numbers is="<<Add/3<<endl<<endl;

break;}

case'3':{

double n6;

cout<<"Please enter a number to find out cube"<<endl;

cin >>n6;

cout<<"cube of number is="<<n6*n6*n6<<endl<<endl;

break;}

case'4':{

int n,factorial=1;

cout<<"Enter number for finding factorial"<<endl;

cin>>n;

for (int i=1;i<=n;i++){

factorial *=i;

}

cout <<"factorial of number is="<< factorial<<endl;

break;

}//case 4

case'5':{

int n,First=0,Second=1,Third;

cout << "Enter any number";

cin >> n;

for (int i = 0; i < n; i++) {

cout << First << endl;

Third=First + Second;

First = Second;

Second= Third;

}//for loop

break;

}

case'6':

{

int num,squar;

cout<<"enter number for square"<<endl;

cin>>num;

squar=num*num;

cout<<"square of number is="<<squar<<endl;

}

}

system("pause");

return 0;

}

**output:**

**1**

Press 1 for Subtraction

Press 2 for average of 3 numbers

Press 3 for cube of number

Press 4 to print the factorial of number

Press 5 to print the Fibonacci series

Press 6 for square of number

Enter two numbers

2

4

substraction of two numbers=-2

**Press 1 for Subtraction**

**Press 2 for average of 3 numbers**

**Press 3 for cube of number**

**Press 4 to print the factorial of number**

**Press 5 to print the Fibonacci series**

**Press 6 for square of number**

2

Enter three number for average

6

7

8

Average of three numbers is=7

**Press 1 for Subtraction**

**Press 2 for average of 3 numbers**

**Press 3 for cube of number**

**Press 4 to print the factorial of number**

**Press 5 to print the Fibonacci series**

**Press 6 for square of number**

3

Please enter a number to find out cube

3

cube of number is=27

**Press 1 for Subtraction**

**Press 2 for average of 3 numbers**

**Press 3 for cube of number**

**Press 4 to print the factorial of number**

**Press 5 to print the Fibonacci series**

**Press 6 for square of number**

5

Enter any number3

0

1

1

**Press 1 for Subtraction**

**Press 2 for average of 3 numbers**

**Press 3 for cube of number**

**Press 4 to print the factorial of number**

**Press 5 to print the Fibonacci series**

**Press 6 for square of number**

6

enter number for square

6

square of number is=36

## 0 Comments