Home
Andy's Blog - Project Euler, Project 5 [entries|archive|friends|userinfo]
Andy

[ website | Portal: Andy ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Project Euler, Project 5 [Apr. 5th, 2009|05:25 pm]
Previous Entry Add to Memories Tell a Friend Next Entry
[Tags|]

http://projecteuler.net/index.php?section=problems&id=5

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

using namespace std;

long start = 1;
long end = 20;

int IsMultiple(long nmbr, long mtpl)
{
        int yesno = 0;
        long multiplier = (long)floor(nmbr / mtpl);
        long temp = mtpl * multiplier;

        if (temp == nmbr)
        {
		yesno = 1;
        }

        return yesno;
}

int main()
{
	int passfail = 0;
	long counter = 1;

	while (passfail == 0)
	{
		passfail = 1;
		
		for (start = 1; start <= end; start++)
		{
			if (IsMultiple(counter, start) == 0)
			{
				passfail = 0;
				break;
			}
		}

		if (passfail == 1) { break; }

		counter++;
	}
	
	cout << counter << endl;

	return 0;
}


I like the Project Euler problems that don't require numeral to character conversion. Much more fun. I also prefer it when the cat waits until I'm finished to come sit in my lap.
LinkReply