Monday, March 19, 2018

write a program by using QBASIC code to input name class and marks obtained in 3 subjects of any one student and calculate total, percentage and display them.


Write a program by using QBASIC code to input name class and marks obtained in 3 subjects of any one student and calculate total, percentage and display them.


CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER CLASS”; C
INPUT “ENTER MARKS OBTAINED IN ANY THREE SUBJECTS”; A, B, C
T = A+ B+ C
P = T / 3
PRINT “YOUR NAME IS”;N$
PRINT “YOUR CLASS IS”; C
PRINT “YOUR OBTAINED MARKS ARE”; A, B, C
PRINT “TOTAL MARKS = “; T
PRINT “PERCENTAGE = “; P
END


Thursday, March 15, 2018

Qbasic Program to display the product of all numbers from 4 to 8 up to 10th terms.

Qbasic Program to display the product of all numbers from 4 to 8 up to 10th terms.

4 देखि 8 सम्म को टेबल लेख 10 टर्म सम्म 

CLS
FOR i = 4 TO 8
    FOR j = 1 TO 10
        PRINT i; "X"; j; "="; i * j
    NEXT j
    PRINT
NEXT i
END

Saturday, March 10, 2018

Qbasic Program that accepts any 12 names and displays the longest among them.

Qbasic Program  that accepts any 12 names and displays the longest among them.

CLS
DIM n(12) AS STRING
FOR i = 1 TO 12
    INPUT "enter 12 names"; n(i)
NEXT i
a$ = n(1)
FOR j = 2 TO 12
    IF LEN(n(j)) > LEN(a$) THEN a$ = n(j)
NEXT j
PRINT "The longest name is: "; a$



END


Qbasic Program that stores system date in a variable and displays the month in word.

Qbasic Program that stores system date in a variable and displays the month in word.

CLS
a = VAL(LEFT$(DATE$, 2))
SELECT CASE a
    CASE 1
        PRINT "Current Month is January"
    CASE 2
        PRINT "Current Month is Feburary"
    CASE 3
        PRINT "Current Month is March"
    CASE 4
        PRINT "Current Month is April"
    CASE 5
        PRINT "Current Month is May"
    CASE 6
        PRINT "Current Month is June"
    CASE 7
        PRINT "Current Month is July"
    CASE 8
        PRINT "Current Month is August"
    CASE 9
        PRINT "Current Month is September"
    CASE 10
        PRINT "Current Month is October"
    CASE 11
        PRINT "Current Month is November"
    CASE 12
        PRINT "Current Month is December"
    CASE ELSE
        PRINT "Wrong Entry"
END SELECT
END


Qbasic Program that accepts date of birth of a person in the MM-DD-YYYY FORMAT AND DISPLAYS THE AGES OF A PERSON.

Qbasic Program that accepts date of birth of a person in the MM-DD-YYYY FORMAT AND DISPLAYS THE AGES OF A PERSON.

CLS
INPUT "enter your date of birth"; d$
p = VAL(RIGHT$(d$, 4))
q = VAL(RIGHT$(DATE$, 4))
r = q - p
PRINT "your age is"; r

END


Qbasic Program to generate the series 3, 5, 8, 12, 17........15th term


Qbasic Program to generate the series 3, 5, 8, 12, 17........15th term

CLS
a = 3
b = 2
FOR i = 1 TO 15
    PRINT a
    a = a + b
    b = b + 1
NEXT i
END

Qbasic Program to generate the series 20, 10, 5, 16.......7th term

Qbasic Program to generate the series 20, 10, 5, 16.......7th term


CLS
a = 20
FOR i = 1 TO 7
    PRINT a
    IF a MOD 2 = 0 THEN
        a = a / 2
    ELSE
        a = a * 3 + 1
    END IF
NEXT i
END

Friday, March 9, 2018

Qbasic Program to Display Common Divisors / Factors of Two Numbers

Qbasic Program to Display Common Divisors / Factors of Two Numbers

DECLARE SUB DISPLAY( )
CLS
INPUT "enter any two numbers"; a, b
CALL DISPLAY (a, b)
END
SUB DISPLAY ( )
WHILE a MOD b <> 0
    r = a MOD b
    a = b
    b = r
WEND
FOR i = 1 TO r
    IF r MOD i = 0 THEN PRINT i,
NEXT i
END SUB

Input : a = 12, b = 24
Output: 6
// all common divisors are 1, 2, 3, 
// 4, 6 and 12

Input : a = 3, b = 17
Output: 1
// all common divisors are 1

Input : a = 20, b = 36
Output: 3
// all common divisors are 1, 2, 4

QBasic Program to check whether the two entered numbers are amicable or not.


QBasic Program to check whether the two entered numbers are amicable or not.

DECLARE SUB amc(a,b)
CLS
INPUT "enter any two numbers"; a, b
CALL amc(a, b)
END
SUB amc (a, b)
FOR i = 1 TO a - 1
    IF a MOD i = 0 THEN s = s + i
NEXT i
FOR j = 1 TO b - 1
    IF b MOD j = 0 THEN t = t + j
NEXT j
IF a = t AND b = s THEN
    PRINT "amicable numbers"
ELSE
    PRINT " not amicable numbers"
END IF


END SUB

Amicable Number Examples: 220, 284

Algorithm :

1. First ask the user to enter both numbers.
2. Find the sum of all divisors for both numbers.
3. Finally check if the sum of the divisors of one number is equal to the other number or not.
4. If yes, it is a Amicable number and otherwise not.