Factorial, Fibonacci and Prime Number in C++ Program


Write a program in C++ that : i) prints the factorial of a given number ii) prints weather a number is prime or not iii) generate a Fibonacci series of 20 numbers.

#include <iostream>
using namespace std;

int main()
{
    int choice, n;
    cout << "\nMenu\n";
    cout << "1. Factorial of given number \n";
    cout << "2. Test Prime Number \n";
    cout << "3. Generate Fibonacci series \n";
    cout << "Enter choice";
    cin >> choice;
    switch (choice)
    {
        case 1:
        {
            int fact = 1;
            cout << "Enter number ";
            cin >> n;
            for (int i = 1; i <= n; i++)
                fact = fact * i;
            cout << "Factorial is " << fact;
        }
        break;
        case 2:
        {
            int flag = 0;
            cout << "Enter number ";
            cin >> n;
            for (int i = 2; i < n; i++)
            {
                if (n % i == 0)
                {
                    cout << "Number is not prime ";
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
                cout << "Number is prime";
        }
        break;
        case 3:
            int first = 0, second = 1, third;
            cout << first << " " << second << " ";
            for (int i = 3; i <= 20; i++)
            {
                third = first + second;
                cout << third << " ";
                first = second;
                second = third;
            }
    }
    return 0;
}