Home  |  IT Zone  |  Tips / Tricks  |  Did You Know  |  Inspirational  |  Health  |  World Infos  |  Insurance  |  Universities  |  Forex  |  Mathematics  |  Illusions  |  Children Day Quotes  |  Fun / Jokes  |  Decent Quotes  |  Birthday Msgs  |  Good Morning Msgs  |  Good Night Msg  |  Husband Wife Jokes  |  Teacher Students Jokes  |  Insult Jokes  |  Love Quotes  |  Sad Quotes  |  Funny Pics  |  Be Aware  |  Articles  |  Simple Joys of Life 

To find the sum of individual digits of the given number. (Qbasic Code)

To find the sum of individual digits of the given number. (Qbasic Code)
  • CLS
    INPUT "Enter a number"; n
    s = 0
    WHILE n <> 0
        r = n MOD 10
        s = s + r
        n = n \ 10
    WEND
    PRINT "The sum of the digits is"; s
    END

Using Sub Procedure
DECLARE SUB sum (n)
CLS
INPUT "Enter a number:"; n
CALL sum(n)
END

SUB sum (n)
        WHILE n <> 0
                r = n MOD 10
                s = s + r
                n = INT(n / 10)
        WEND
   PRINT s
END SUB



Using Function Procedure
DECLARE FUNCTION sum (n)
CLS
INPUT "Enter a number:"; n
s = sum(n)
PRINT "The sum of the digits is";s
END

FUNCTION sum (n)
        WHILE n <> 0
                r = n MOD 10
                s = s + r
                n = INT(n / 10)
        WEND
        sum = s
END FUNCTION

Share :

Twitter
Back To Top

facebook main

Powered by Blogger.