C0d3-R

Programando por convicción

Más código

Hace cerca de un mes que me inscribí en la web de project euler, dónde existen muchos problemas matemáticos los cuales debemos darles solución con un algoritmo, sea en el elnguaje que sea.

Dejo algunos que he resuelto:

#include <stdio.h>

main()

{
printf(“Problema 05\n”);
register int i=1;
int j=2520;
int tmp=1;
int resultado=0;
while(j>0)
{
i=1;
tmp=i;
while(i<=20)
{
resultado=j%i;
if(resultado==0)
{
tmp++;

if(tmp==20)
{
printf(“j: %d i: %d tmp: %d\n”, j, i, tmp);
break;
}

}
else
{
break;
}
i++;
}
if(tmp==20)
{
break;
}
j++;
}

}

Problema 5

/*
The sum of the squares of the first ten natural numbers is,
12 + 22 + … + 102 = 385

The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)2 = 552 = 3025

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.
*/

#include <stdio.h>
#include <math.h>

main()
{
double res=0;
int i=0;
double tmp=0;
double tmp2=0;
while(i<=100)
{

res=pow(i, 2);
tmp+=res;
printf(“El cuadrado es: %f, la sumatoria es: %f\n”, res, tmp);
tmp2+=i;
if(i==100)
{
tmp2=pow(tmp2, 2);
printf(“La sumatoria dos es %f\n”, tmp2);
double fin = tmp2-tmp;
printf(“Final: %f\n”, fin);
}
i++;
}

}

Problema 6…

No es la gran cosa, pero me entetienen bastante

saludos

noviembre 19, 2008 Publicado por | Programación en C | Dejar un comentario

   

Seguir

Get every new post delivered to your Inbox.