Sha256: 1d45c0d95124c61e79592f2b2080d51465f23ce0b2c97671585cb781c5796b5b

Contents?: true

Size: 431 Bytes

Versions: 396

Compression:

Stored size: 431 Bytes

Contents

#include "difference_of_squares.h"
#include <algorithm>

using namespace std;

namespace squares
{

int square_of_sums(int n)
{
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        sum += i;
    }
    return sum*sum;
}

int sum_of_squares(int n)
{
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        sum += i*i;
    }
    return sum;
}

int difference(int n)
{
    return square_of_sums(n) - sum_of_squares(n);
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.97 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.96 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.95 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.94 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.93 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.92 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.91 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.90 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.89 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.88 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.87 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.86 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.85 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.84 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.83 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.82 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.81 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.80 tracks/cpp/exercises/difference-of-squares/example.cpp
trackler-2.2.1.79 tracks/cpp/exercises/difference-of-squares/example.cpp