Jim

3 problems has been added

Solved problems from projecteuler.net
... ...
No preview for this file type
#include "stdio.h"
#define PRECIS 1000
int multiple (int n){
int i;
int result;
int summ;
result = 0;
summ =0;
i = 1;
while (result < PRECIS){
summ += result;
printf ("Result :%i\t Summ:%i\n",result, summ);
result = n*i;
i++;
}
return summ;
}
int multiple_check (int n, int m){
int i;
int result;
int summ;
result = 0;
summ =0;
i = 1;
while (result < PRECIS){
if ( (result % m)) {
summ += result;
printf ("Result :%i\t Summ:%i\n",result, summ);
}
else {
printf ("Do nothing! :)\n");
}
result = n*i;
i++;
}
return summ;
}
main () {
int total;
int total1;
int total2;
total1 = multiple(3);
total2 = multiple_check(5,3);
total = total1 + total2;
printf ("Total1: %i Total2: %i Total: %i\n ", total1, total2, total);
return 0;
}
... ...
No preview for this file type
#include "stdio.h"
#define STEP 4000000
main () {
long int sum;
int one, two, three;
one=1;
two=2;
three = 0;
sum = 0;
while (two <= STEP){
three = one + two;
// printf ("%i,", three);
if ( (two % 2 ) == 0)
sum += two;
// printf ("sum is now: %lu\n", sum);
one = two;
two = three;
}
printf ("Sum = %lu\n", sum);
return 0;
}
... ...
#include <stdio.h>
#include <math.h>
#define NUMBER 600851475143
void primefactors(long int n){
long int i;
while (n % 2 == 0){
printf ("1 %i\n" , 2);
n = n/2;
}
for (i=3; i <= sqrt(n); i= i+2){
while (n % i == 0){
printf("2 %li\n", i);
n = n/i;
}
}
if (n > 2)
printf ("3 %li\n", n);
}
main () {
primefactors (NUMBER);
return 0;
}
... ...
No preview for this file type
#include <stdio.h>
#include <math.h>
#define NUMBER 600851475143
void primefactors(long int n){
long int i;
while (n % 2 == 0){
printf ("1 %i\n" , 2);
n = n/2;
}
for (i=3; i <= sqrt(n); i= i+2){
while (n % i == 0){
printf("2 %li\n", i);
n = n/i;
}
}
if (n > 2)
printf ("3 %li\n", n);
}
main () {
primefactors (NUMBER);
return 0;
}
... ...