6 - sum square difference

The sum of the squares of the first ten natural numbers is,

sum_square_difference

The square of the sum of the first ten natural numbers is,

sum_square_difference

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

link

cevap : 25164150

#include <stdio.h>
#pragma hdrstop
#include <tchar.h>
#include "math.h"

// fonksiyon prototipleri
void kareleri_hesapla_dizide_tut(unsigned int kare[100]);
unsigned int kareleri_topla(unsigned int kare[100]);
unsigned int sayilari_topla();

// global degiskenler

#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
    unsigned int kare[100];
    unsigned int karelerin_toplami;
    unsigned int sayilarin_toplami;
    unsigned int sayilarin_toplaminin_karesi;
    unsigned int fark;

    kareleri_hesapla_dizide_tut(kare);
    karelerin_toplami = kareleri_topla(kare);

    sayilarin_toplami = sayilari_topla();
    sayilarin_toplaminin_karesi = sayilarin_toplami*sayilarin_toplami;

    fark = abs(sayilarin_toplaminin_karesi - karelerin_toplami);

    printf("Sonuc = %d\n",fark);

    system("pause");
}

void kareleri_hesapla_dizide_tut(unsigned int kare[100]) {

    unsigned int i;

    for (i = 1; i < 101; i++) {
        kare[i-1] = i*i;
    }
}

unsigned int kareleri_topla(unsigned int kare[100]){

    unsigned int i;
    unsigned int karelerin_toplami = 0;

    for (i = 1; i < 101; i++) {
        karelerin_toplami = karelerin_toplami + kare[i-1];
    }

    return karelerin_toplami;
}

unsigned int sayilari_topla(){

    unsigned int i;
    unsigned int sayilarin_toplami = 0;

    for(i=1; i<101; i++){
        sayilarin_toplami = sayilarin_toplami + i;
    }

    return sayilarin_toplami;
}