Sunday, July 10, 2011

Friday, July 8, 2011

Program

1) WAP to print the Fibonacci series
CLS
a = 1
b = 1
PRINT a, b,
FOR i = 1 TO 8
c = a + b
PRINT c,
a = b
b = c
NEXT i
END
……………………………………………………………………………….

2) WAP to print the factors of a given number
REM Program to print the factors of a given number
CLS
INPUT “Enter any number”; n
FOR i = 1 TO n
IF n MOD i = 0 THEN PRINT i,
NEXT i
END
…………………………………………………………………………………

3) WAP to print the greater among ten different numbers
REM Program to print greater number among ten different numbers
CLS
INPUT “Enter first number”; g
FOR i = 2 TO 10
INPUT “Enter next number”; a
IF a > g THEN g = a
NEXT
PRINT g; ” is the greatest number”
END

………………………………………………………………………………….
4) WAP to print the greater among three different numbers
REM Program to print greater among three different numbers
CLS
INPUT “Enter first number”; a
INPUT “Enter second number”; b
INPUT “Enter third number”; c
IF a > b AND a > c THEN
PRINT a; ” is greater”
ELSEIF b > a AND b > c THEN
PRINT b; ” is greater”
ELSE
PRINT c; ” is greater”
END IF
END
…………………………………………………………………………….

5) WAP to print the greater among two different numbers
REM Program to print the greater among two different numbers
CLS
INPUT “Enter first number”; a
INPUT “Enter second number”; b
IF a > b THEN
PRINT a; ” is greater”
ELSE
PRINT b; ” is greater”
END IF
END
………………………………………………………………………………..
6) WAP to calculate the cube root of a given number
REM Program to calculate the cube root of a given number
CLS
INPUT “Enter any number”; n
c = n ^ (1 / 3)
PRINT “Cube root of “; n; ” is “; s
END
…………………………………………………………………………………..

7) WAP to calculate the square root of a given number
REM Program to calculate the square root of a given number
CLS
INPUT “Enter any number”; n
s = SQR(n)
PRINT “Square root of “; n; ” is “; s
END
…………………………………………………………………………………..
8) Program to check the given number for palindrome in qbasic using declare sub
DECLARE SUB A (N)
CLS
INPUT “ENTER A NUMBER”; N
CALL A(N)
END
SUB A (N)
S = N
WHILE N <> 0
B = N MOD 10
R = R * 10 + B
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “IT IS PALINDROME”
ELSE
PRINT “IT IS NOT PALINDROME”
END IF
END SUB

………………………………………………………………………………..
9) Program to check given number for armstrong in qbasic using declare sub
DECLARE SUB A(N)
CLS
INPUT “ENTER A NUMBER”; N
CALL A(N)
END
SUB A(N)
S=N
WHILE N <> 0
B = N MOD 10
R = R + B ^ 3
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS ARMSTRONG”
ELSE
PRINT “IT IS NOT ARMSTRONG”
END IF
END SUB
………………………………………………………………………………….

10) Program to reverse a given string in qbasic
CLS
INPUT “ENTER A STRING”; S$
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
PRINT REV$
END

………………………………………………………………………………..

11s) Program to convert decimal to binary in qbasic using declare function
DECLARE FUNCTION A$ (N)
CLS
INPUT “ENTER A NUMBER”; N
PRINT “BINARY EQUIVALENT IS”; A$(N)
END

FUNCTION A$ (N)
WHILE N <> 0
E = N MOD 2
B$ = STR$(E)
N = FIX(N / 2)
C$ = B$ + C$
WEND
A$=C$
END FUNCTION
………………………………………………………………………………….
Click here for more programs