another programming question

Discussion in 'Web Design & Coding' started by mooo, Jan 27, 2004.

  1. mooo

    mooo thecyberninja

    Messages:
    886
    Location:
    earth
    was thinking about just putting this in other post but wasn't sure.

    Say i input 4 numbers (we will use 3456), is there a way to just add the numbers like 3+4+5+6=x .. i was thinking a while loop but i am not sure how to make it read one place when you have to input the whole number at once. Does anyone know a formula that might do this? thanks in advance.

    mooo


    (mod if you thinkit should be moved pls do, was not sure if i should or not)
     
  2. mooo

    mooo thecyberninja

    Messages:
    886
    Location:
    earth
    nm, figured it out i think

    if (n==0) {return 0)
    else
    return (n%10) + calcular(n/10);