Math: Triangular Numbers

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

<— Return Home

61.cpp

#include <iostream>
using namespace std;

int getTriangularNumber(int n){
    return n * (n + 1) / 2;
}

int main(){
    int counter = 0;
    for (int i = 0; i < 75; i++){
        if (counter == 5){
            std::cout << "\n";
            counter = 0;
        }
        std::cout << getTriangularNumber(i) << " ";
        counter++;
    }
    std::cout << "\n";
}

<— Return Home