Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

x and y

  • 30-10-2003 8:55pm
    #1
    Closed Accounts Posts: 4


    i have to input two numbers X and Y, now i have to find the sum of the squares, of the numbers between X and Y which are even, anyone got any ideas, any help would be grat thanks :)


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    This is a p!sstake?


  • Closed Accounts Posts: 4 kero


    no not a piis take just a question, havent got a clue about vb, friend of mine is doing an assingnment and this was one of the q,s which were part of it you dont have to help, but if your not going to bother helping you might as well refrain from commenting


  • Closed Accounts Posts: 1,819 ✭✭✭K!LL!@N


    I'd suggest maybe posting up some of the attempts you've made, at solving this problem, yourself.
    Otherwise people will think you're just trying to get others to do your homework.

    Killian


  • Registered Users, Registered Users 2 Posts: 19,608 ✭✭✭✭sceptre


    Originally posted by kero
    havent got a clue about vb
    Ah, does that mean you're doing the above in vb then (cos you didn't mention that in the first post so no-one knew what you were at)?


  • Closed Accounts Posts: 4 kero


    :P opps sorry

    here we go,
    one attempt so far

    total = 0
    num = 0
    Do
    total = total + (num ^ num)
    num = num + 1
    Loop until num = x

    This is to add together all the squares of the numbers between 1 and x.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Well you might of mentioned VB to begin with.

    Still sounds like a homework question.

    Use FOR loops.


  • Closed Accounts Posts: 4 kero


    well i did just say it was a assignment...

    theres seven parts to the assingment (homework)
    you have to use the 3 types of loops and spread them out evenly, used 3 'for loops' already so dont want to use anymore... thats why we're looking for another way


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,567 Mod ✭✭✭✭Capt'n Midnight


    The sum of the even squares between X and Y..

    Hint 1 - Odd numbers multiplied by each other are odd.
    Hint 2 - Start at Sqrt(X)
    Hint 3 - use integers.
    Hint 4 - (A\2)*2 , Int(A/2) + Int(A/2) etc. to get even numbers
    or if you are using integers A/2+A/2 might work

    PS. if it was just the squares of the even numbers between x and y - try to find a more interesting problem


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Capt'n Midnight
    The sum of the even squares between X and Y..

    is not what the question asked for....

    I'd offer some ideas myself except that the sample poster by kero is only missing two things :

    1) How do I start at some point other than 1
    2) How do I skip the odd numbers

    Given that one is solved by an assignment, and the other by an if statement, I don't think there's really much left to do...he/she has already done all the hard work.

    jc


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Originally posted by bonkey
    1) How do I start at some point other than 1
    2) How do I skip the odd numbers

    Something like...
    FOR n = x TO y STEP s
    
    NEXT n
    
    To make sure it is only even, you would have to increment X if it is odd to begin with. For only even numbers then s would be equal to 2.


  • Advertisement
  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,567 Mod ✭✭✭✭Capt'n Midnight


    REPLY
    is not what the question asked for....
    PS. if it was just the squares of the even numbers between x and y - try to find a more interesting problem

    I'd offer some ideas myself except that the sample poster by kero is only missing two things :

    1) How do I start at some point other than 1
    Hint 4 - (A\2)*2 , Int(A/2) + Int(A/2) etc. to get even numbers
    or if you are using integers A/2+A/2 might work


    2) How do I skip the odd numbers

    Given that one is solved by an assignment, and the other by an if statement, I don't think there's really much left to do...he/she has already done all the hard work.

    jc
    ========================
    [php]
    total = 0
    num = 0
    Do
    total = total + (num ^ num)
    num = num + 1
    Loop until num = x
    [/php]

    [php]
    if (x mod 1)
    then
    x=x+1
    end if
    Do
    total = total + (x*x)
    incr x
    incr x
    Loop until x >=y
    [/php]
    the bit at the top might make x even - there are other ways
    2 incr's x=x+2 => still even


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Originally posted by kero
    well i did just say it was a assignment...
    You see, the correct way to ask for help in an assignment is something like this:

    Look this is for an assignment, and I know the rules [not reading the rules is against the rules and punished by a lifetime ban] but I've been trying already and here are a few things I tried and the results I got with them [insert at least two examples of reasonable things you tried and what happened when you tried them] does anyone have any pointers that could help me.


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    swift kick in the booty


Advertisement