Jim

3 problems has been added

  1 +Solved problems from projecteuler.net
No preview for this file type
  1 +#include "stdio.h"
  2 +
  3 +#define PRECIS 1000
  4 +
  5 +int multiple (int n){
  6 +
  7 + int i;
  8 + int result;
  9 + int summ;
  10 + result = 0;
  11 + summ =0;
  12 + i = 1;
  13 +
  14 + while (result < PRECIS){
  15 + summ += result;
  16 + printf ("Result :%i\t Summ:%i\n",result, summ);
  17 + result = n*i;
  18 + i++;
  19 + }
  20 +
  21 + return summ;
  22 +}
  23 +
  24 +int multiple_check (int n, int m){
  25 +
  26 + int i;
  27 + int result;
  28 + int summ;
  29 + result = 0;
  30 + summ =0;
  31 + i = 1;
  32 +
  33 + while (result < PRECIS){
  34 + if ( (result % m)) {
  35 + summ += result;
  36 + printf ("Result :%i\t Summ:%i\n",result, summ);
  37 + }
  38 + else {
  39 + printf ("Do nothing! :)\n");
  40 + }
  41 + result = n*i;
  42 + i++;
  43 +
  44 + }
  45 +
  46 + return summ;
  47 +}
  48 +
  49 +main () {
  50 + int total;
  51 + int total1;
  52 + int total2;
  53 + total1 = multiple(3);
  54 + total2 = multiple_check(5,3);
  55 + total = total1 + total2;
  56 + printf ("Total1: %i Total2: %i Total: %i\n ", total1, total2, total);
  57 +
  58 + return 0;
  59 +}
No preview for this file type
  1 +#include "stdio.h"
  2 +
  3 +#define STEP 4000000
  4 +
  5 +main () {
  6 +
  7 + long int sum;
  8 + int one, two, three;
  9 +
  10 + one=1;
  11 + two=2;
  12 + three = 0;
  13 + sum = 0;
  14 + while (two <= STEP){
  15 +
  16 + three = one + two;
  17 +// printf ("%i,", three);
  18 +
  19 + if ( (two % 2 ) == 0)
  20 + sum += two;
  21 +// printf ("sum is now: %lu\n", sum);
  22 + one = two;
  23 + two = three;
  24 +
  25 +
  26 +
  27 + }
  28 +
  29 + printf ("Sum = %lu\n", sum);
  30 +
  31 + return 0;
  32 +}
  1 +#include <stdio.h>
  2 +#include <math.h>
  3 +
  4 +#define NUMBER 600851475143
  5 +
  6 +void primefactors(long int n){
  7 +
  8 + long int i;
  9 +
  10 + while (n % 2 == 0){
  11 + printf ("1 %i\n" , 2);
  12 + n = n/2;
  13 + }
  14 +
  15 + for (i=3; i <= sqrt(n); i= i+2){
  16 + while (n % i == 0){
  17 + printf("2 %li\n", i);
  18 + n = n/i;
  19 + }
  20 + }
  21 +
  22 + if (n > 2)
  23 + printf ("3 %li\n", n);
  24 +}
  25 +
  26 +
  27 +main () {
  28 +
  29 + primefactors (NUMBER);
  30 +
  31 + return 0;
  32 +}
No preview for this file type
  1 +#include <stdio.h>
  2 +#include <math.h>
  3 +
  4 +#define NUMBER 600851475143
  5 +
  6 +void primefactors(long int n){
  7 +
  8 + long int i;
  9 +
  10 + while (n % 2 == 0){
  11 + printf ("1 %i\n" , 2);
  12 + n = n/2;
  13 + }
  14 +
  15 + for (i=3; i <= sqrt(n); i= i+2){
  16 + while (n % i == 0){
  17 + printf("2 %li\n", i);
  18 + n = n/i;
  19 + }
  20 + }
  21 +
  22 + if (n > 2)
  23 + printf ("3 %li\n", n);
  24 +}
  25 +
  26 +
  27 +main () {
  28 +
  29 + primefactors (NUMBER);
  30 +
  31 + return 0;
  32 +}