Hack Forums
[Source] Print Multiplication Table (C++) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Source] Print Multiplication Table (C++) (/showthread.php?tid=6269099)



Print Multiplication Table (C++) - Emre_ - Apr 21, 2024

Code
#include <iostream>
#include <stdlib.h>
using namespace std;

void Clear()
{
#if defined _WIN32
    system("cls");
#elif defined (__LINUX__) || defined(__gnu_linux__) || defined(__linux__) || defined (__APPLE__)
    system("clear");
#endif
}

int main()
{
    int j, i, n;

    cout << "\n Input the number upto 10: ";
    cin >> n;
    Clear();
    cout << "\nMultiplication table from 1 to " << n << endl;
    ;
    cout << "--------------------------------------------------------------------------------\n";



    for (i = 1; i <= 10; i++)
    {
        for (j = 1; j <= n; j++)
        {
            if (j <= n - 1)
                cout << j << "x" << i << "=" << i * j << " ";
            else
                cout << j << "x" << i << "=" << i * j << " ";
        }
        cout << endl;

    }

    cout << '\n' << '\n';
    system("pause");

    cout << "\n\nPress the enter key to exit";



    return 0;
}