Jump to content

Just a quick question hoping to get it answered quickly

 

How many characters is in the answer of Project Euler 1?

My current total has 8 Characters in it,

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/
Share on other sites

Link to post
Share on other sites

6

 

(Did it two days ago :P  )

Ryzen 7 5800X     Corsair H115i Platinum     ASUS ROG Crosshair VIII Hero (Wi-Fi)     G.Skill Trident Z 3600CL16 (@3800MHzCL16 and other tweaked timings)     

MSI RTX 3080 Gaming X Trio    Corsair HX850     WD Black SN850 1TB     Samsung 970 EVO Plus 1TB     Samsung 840 EVO 500GB     Acer XB271HU 27" 1440p 165hz G-Sync     ASUS ProArt PA278QV     LG C8 55"     Phanteks Enthoo Evolv X Glass     Logitech G915      Logitech MX Vertical      Steelseries Arctis 7 Wireless 2019      Windows 10 Pro x64

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/#findComment-2798628
Share on other sites

Link to post
Share on other sites

  • 1 month later...

Thanks...

Probably shouldn't Write the total to the Console every time...

Took a break off of this, and decided to try again. :P

I'm sure theirs nothing wrong with this: (C++)

#include <iostream>using namespace std;int main(){    int sum, upto, c;    upto = 1000;    for (c = 0; c <= upto; c++){        if (c % 3 == 0 || c % 5 == 0){                // Save that nanoseconds worth of time.            if (c % 3 == 0 && c % 5 == 0) {                sum = sum + c;                cout << "3 & 5 are multiples of " << c << endl;            } else {                if (c % 3 == 0)                {                    sum = sum + c;                    cout << "3 is a multiple of " << c << endl;                }                if (c % 5 == 0)                {                    sum = sum + c;                    cout << "5 is a multiple of " << c << endl;                }            }        } else {            cout << c << " Checked." << endl;        }    }    cout << sum << endl;    return 0;}

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/#findComment-3172965
Share on other sites

Link to post
Share on other sites

Because 3 & 5 would be multiples, will try without.

Edit: Still wrong will edit above post.

You never initialize sum to 0, depending on your compiler that could be the problem, without the *2 it comes up with the correct solution for me.

1474412270.2748842

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/#findComment-3173267
Share on other sites

Link to post
Share on other sites

You never initialize sum to 0, depending on your compiler that could be the problem, without the *2 it comes up with the correct solution for me.

I initialized the sum and removed the *2, I'm assuming that I'm much closer to the answer (234168).

Not sure what could be wrong at the moment.

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/#findComment-3173328
Share on other sites

Link to post
Share on other sites

I initialized the sum and removed the *2, I'm assuming that I'm much closer to the answer (234168).

Not sure what could be wrong at the moment.

You changed

for (c = 0; c < upto; c++){

to

for (c = 0; c <= upto; c++){

it was right the first time.

1474412270.2748842

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/#findComment-3173381
Share on other sites

Link to post
Share on other sites

You changed

for (c = 0; c < upto; c++){

to

for (c = 0; c <= upto; c++){

it was right the first time.

Aye, Thanks :)

Just realized that, the code above could be compacted to 20 lines. ...

Edited by AustinB

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
https://linustechtips.com/topic/206185-project-euler-1/#findComment-3173422
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×