QBASIC
1. WAP to print all odd numbers between 1 to 50.
CLS
FOR I = 1 TO 50 STEP 2
PRINT I
NEXT I
END
2. WAP to print all the even numbers between 2 to 50 in the descending order.
CLS
FOR I = 2 TO 50 STEP 2
PRINT I
NEXT I
END
3. WAP to print the multiplication table of given number upto 10 terms.
CLS
INPUT "ENTER THE NUMBER ";N
FOR I = 1 TO 10
PRINT 2 "*" 1 "=" N*I
NEXT I
END
4. WAP to input any 5 number and print them on ascending order.
CLS
DIM N(10)
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
FOR I = 1 TO 10
FOR J = 1 TO 10 - I
IF N(J) > N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I
PRINT "NUMBERS ARRANGED IN ASCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I
END
USING SUB PROCEDURE
DECLARE SUB SORT (N())
CLS
DIM N(10)
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
CALL SORT(N())
PRINT "NUMBERS ARRANGED IN ASCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I
END
SUB SORT (N())
FOR I = 1 TO 10
FOR J = 1 TO 10 - I
IF N(J) > N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I
END SUB
WAP to input any 5 number and print them on descending order.
CLS
DIM N(10)
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
FOR I = 1 TO 10
FOR J = 1 TO 10 - I
IF N(J) < N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I
PRINT "NUMBERS ARRANGED IN DESCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I
END
USING SUB PROCEDURE
DECLARE SUB SORT (N())
CLS
DIM N(10)
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS"; N(I)
NEXT I
CALL SORT(N())
PRINT "NUMBERS ARRANGED IN DESCENDING ORDER"
FOR I = 1 TO 10
PRINT N(I)
NEXT I
END
SUB SORT (N())
FOR I = 1 TO 10
FOR J = 1 TO 10 - I
IF N(J) < N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I
END SUB
1. Write programs to generate the following number series.
A. 1, 3, 5, 7, ........... 57
CLS
FOR I = 1 TO 57 STEP 2
PRINT I;
NEXT I
END
B. 5, 7, 9, .......... up to 25th term.
CLS
a = 5
FOR i = 1 TO 25
PRI NT a;
a = a + 2
NEXT i
End
C. 1, 4, 9, ........... up to 15 terms.
CLS
FOR I = 1 TO 15
B = I*I
PRINT B;
NEXT I
END
D. -20, -15, -10, ........ up to 12 terms.
CLS
a = -20
FOR i = 1 TO 12
PRINT a;
a = a + 5
NEXT i
END
e. 90, 80, 70, ......... 10
CLS
FOR I = 90TO 10 STEP -10
PRINT I;
NEXT I
END
F. 1, 11, 111, 1111, 11111
CLS
a = 1
FOR i = 1 TO 5
PRINT a;
a = a * 10 + 1
NEXT i
END
G. 2, 22, 222, 2222, 22222
CLSa = 2
FOR i = 1 TO 5
PRINT a;
a = a * 10 + 2
NEXT iEND
H. 33333, 3333, 333, 33, 3
CLS
a = 33333
FOR i = 1 TO 5
PRINT a;
a = a \ 10
NEXT i
END
I. 4, .4, .04, 004, .0004, .00004
CLS
a = 4
FOR i = 1 TO 6
PRINT a;
a = a / 10
NEXT i
END
J. 1,.3, .05, .007, .0009
CLS
a = 10
FOR j = 1 TO 9 STEP 2
PRINT j / a;
a = a * 10
NEXT
END
k. 2, 8, 18, 32, .... up to 10 terms.
CLS
FOR I = 1 TO 10
PRINT 2*I^2;
NEXT I
END
L. 2, 4, 7, 11, 16, ..... up to 13 terms.
CLS
a = 1
b = 2
FOR i = 1 TO 13
a = a + 1
FOR j = 1 TO 1
PRINT b;
b = b + a
NEXT j
NEXT i
END
M. 2, 3, 5, 8, 12, 17, .... Up to 14th term.
CLS
a = 0
b = 2
FOR i = 1 TO 14
a = a + 1
FOR j = 1 TO 1
PRINT b;
b = b + a
NEXT j
NEXT i
END
N. 2, 4, 8, 14, 22, 32, ...... up to 10th term.
CLS
a = 0
b = 2
FOR i = 1 TO 10
a = a + 2
FOR j = 1 TO 1
PRINT b;
b = b + a
NEXT j
NEXT i
END
O. 2, 4, 12, 48, ...... up to 10 terms.
CLS
a = 2
b = 2
FOR i = 1 TO 10
PRINT a
a = a * b
b = b + 1
NEXT i
END
P. 5, 50, 500, 5000, 50000
CLS
a = 5
FOR i = 1 TO 5
PRINT a;
a = a * 10
NEXT i
END
R. 1, 22, 333, 4444, 55555
CLS
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT i;
NEXT j
NEXT i
END
2. Write the program to generate the following fibonacci series.
A. 1,1,2,3,5, 8, ....... up to the 13th term.
CLS
a = 1
b = 1
PRINT a; b;
FOR i = 1 TO 11
c = a + b
PRINT c;
a = b
b = c
NEXT i
END
B. 2, 2, 4, 6, 10, 16, ...... up to 12 terms.
CLS
a = 2
b = 2
PRINT a; b;
FOR i = 1 TO 10
c = a + b
PRINT c;
a = b
b = c
NEXT i
END
C. 1,3,4, 7, 11, 18, ...... up to 13th term.
CLS
a = 1
b = 3
PRINT a; b;
FOR i = 1 TO 11
c = a + b
PRINT c;
a = b
b = c
NEXT i
END
3. Write a program to display sum of even numbers from the set of numbers: 5, 7, 8, 12.9.11,6 and 24
CLS
a = 5
b = 7
c = 8
d = 12
e = 9
f = 11
g = 6
h = 24
IF (a MOD 2) = 0 THEN
i = i + a
END IF
IF (b MOD 2) = 0 THEN
i = i + b
END IF
IF (c MOD 2) = 0 THEN
i = i + c
END IF
IF (d MOD 2) = 0 THEN
i = i + d
END IF
IF (e MOD 2) = 0 THEN
i = i + e
END IF
IF (f MOD 2) = 0 THEN
i = i + f
END IF
IF (g MOD 2) = 0 THEN
i = i + g
END IF
IF (h MOD 2) = 0 THEN
i = i + h
END IF
PRINT i;
END
4. Write a program that accepts any two integers and displays the H.CF and LCM of them
CLS
INPUT "enter any two numbers:", A, B
C = A
D = B
WHILE A MOD B <> 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
PRINT "HCF:", B
PRINT "LCM:", L
END
5. WAP that accepts any ten numbers from the user and displays the greatest and smallest among them.
CLS
INPUT "enter any number"; a
b = a
FOR i = 1 TO 9
INPUT "enter next number"; c
IF (c > a) THEN
a = c
END IF
IF (c < b) THEN
b = c
END IF
NEXT i
PRINT a; "is the greatest number"
PRINT b; "is the smallest number"
END
6. WAP that reads a list of numbers and displays the smallest and greatest number. The list of numbers contains 45, 46, 78, 12, 32, 11, 124, -1 and -5.
CLS
FOR i = 1 TO 9
READ n
IF (a < n) THEN
b = n
END IF
IF (a > n) THEN
c = n
END IF
DATA 45,46,78,12,32,11,124,-1,-5
NEXT i
PRINT b; "is the largest number"
PRINT c; "is the smallest number"
END
7. Write a program to accept an integer and display factors of it. The program also counts and displays number of factors
CLS
INPUT "Enter any number"; a
IF (a <> 0) THEN
FOR i = 1 TO a
IF (a MOD i) = 0 THEN
PRINT i; "is a factor of"; a
c = c + 1
END IF
NEXT i
PRINT a; "has"; c; "factors"
ELSE
PRINT "Enter the number exect it"
END IF
END
8. Write a program to accept an integer and display the sum of the factors of it.
CLS
INPUT "Enter any number"; a
IF (a <> 0) THEN
FOR i = 1 TO a
IF (a MOD i) = 0 THEN
c = c + i
END IF
NEXT i
PRINT c; "is the sum of factor of"; a
ELSE
PRINT "Enter the number exect it"
END IF
END
9. Write a program to accept an integer and display the product of the factors of it.
CLS
c = 1
INPUT "Enter any number"; a
IF (a <> 0) THEN
FOR i = 1 TO a
IF (a MOD i) = 0 THEN
c = c * i
END IF
NEXT i
PRINT c; "is the product of factor of"; a
ELSE
PRINT "Enter the number exect it"
END IF
END
10. Write a program to check whether input number is prime or composite
CLS
INPUT "enter any number"; a
IF (a <> 0) AND (a <> 1) THEN
FOR i = 1 TO a
IF (a MOD i) = 0 THEN
c = c + 1
END IF
NEXT i
IF (c = 2) THEN
PRINT a; "is prime number"
ELSE
PRINT a; "is composite number"
END IF
ELSE
PRINT "input valid number"
END IF
END
11. Write a program to display a list of prime numbers from 1 to 25.
CLS
FOR i = 1 TO 25
c = 0
FOR j = 1 TO i
IF i MOD j = 0 THEN
c = c + 1
END IF
NEXT j
IF c = 2 THEN
PRINT i,
END IF
NEXT i
END
12. Write a program to display the list of composite numbers from 1 to 20
CLS
FOR i = 1 TO 25
c = 0
FOR j = 1 TO i
IF i MOD j = 0 THEN
c = c + 1
END IF
NEXT j
IF c > 2 THEN
PRINT i,
END IF
NEXT i
END
13. Write a program to display the first twelve prime numbers.
CLS
FOR i = 1 TO 40
c = 0
FOR j = 1 TO i
IF i MOD j = 0 THEN
c = c + 1
END IF
NEXT j
IF c = 2 THEN
PRINT i,
END IF
NEXT i
END
14. Write a program to display the first 15 composite numbers.
CLS
FOR i = 1 TO 25
c = 0
FOR j = 1 TO i
IF i MOD j = 0 THEN
c = c + 1
END IF
NEXT j
IF c > 2 THEN
PRINT i,
END IF
NEXT i
END
15. Write a program to accept an integer and check whether the number is a perfect number not.
CLS
INPUT "enter any number"; a
FOR i = 1 TO a
IF (a MOD i) = 0 THEN
IF (i <> a) THEN
c = c + i
END IF
END IF
NEXT i
IF (a = c) THEN
PRINT a; "is a perfect number"
ELSE
PRINT a; "is not a perfect number"
END IF
END
0 Comments