Q-BASIC Program (WAP to find a factor, reverse order, series, palindrome, Armstrong, prime, and composite)
Write a program to display the following series:
1. 3 9 27 81............. up to 10th terms
CLS
FOR X=1 TO 10
N=3^X
PRINT N;
NEXT X
END
2. 100 97.5 95 92.51....up to 10th terms
CLS
N=100
FOR I = 1 TO 10
PRINT N;
N = N-2.5
NEXT I
END
3. 7 77 777 7777 77777
CLS
A=7
FOR I=1 TO 5
PRINT A;
A-A*10+7
NEXT I
END
4. 2 1 3 4 7 -------------- UP TO 10TH TERMS. (FIBONACCI SERIES)
CLS
A=2
B=1
PRINT A; B;
FOR 1=1 TO 8
C=A+B
PRINT C;
A=B
B=C
NEXT 1
END
Or
CLS
A=2
B=1
FOR 1-1 TO 5
PRINT A; B;
A=A+B
B=A+B
NEXT I
END
5. 55555 5555 555 55 5
CLS
P=55555
X=1
WHILE X<=5
PRINT P;
P=P\10
X=X+1
WEND
END
6. Write a program to display the factorial of a given number.
CLS
INPUT "Enter a number"; N
P=1
FOR I=1 TO N
P=P*I
NEXT I
PRINT "Factorial is;" ;P
END
7. Write a program to input any input number and print it in reverse order.
CLS
INPUT "Enter any number"; N
WHILE N<>0
R=N MOD 10
S= (S*10)+R
N=N\10
WEND
PRINT "Reverse of the given number is"; S
END
8. Write a program to input any number and display the sum of individual digits of the given number.
CLS
INPUT "Enter any number"; N
WHILE N<> 0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT "The sum of individual digits is"; S
END
9. Write a program to display the factors of the given number.
CLS
INPUT "Enter a number"; NUM
FOR I= 1 TO NUM
IF NUM MOD I=0 THEN
PRINT I;
END IF
NEXT I
END
10. Write a program to enter a number and check whether the number is palindrome or not.
CLS
INPUT "Enter a number"; N
P=N
DO WHILE N<>0
R=N MOD 10
S=S*10+R
N=N\10
LOOP
IF P=S THEN
PRINT "The number is a palindrome"
ELSE
PRINT "The number is not a palindrome"
END IF
END
11. Write a program to input a number and check whether the number is Armstrong or not. The number is called Armstrong if the sum of the cubes of each individual digit is equal to the given number]
CLS
INPUT "Enter a number"; N
P=N
WHILE NO
R=N MOD 10
A=A+R^3
N= N \ 10
WEND
IF A =P THEN
PRINT "The number is Armstrong"
ELSE
PRINT "The number is not Armstrong"
ENDIF
END
12. Write a program to input any number from the user and then display whether it is prime or composite.
CLS
INPUT "ENTER ANY NUMBER"; N
FOR I=1 TO N
R=N MOD I
IF R=0 THEN
C=C+1
ENDIF
NEXT I
IF C=2 THEN
PRINT "THE GIVEN NUMBER IS PRIME"
ELSE
PRINT "THE GIVEN NUMBER IS COMPOSITE"
ENDIF
END
13. Write a program to display all the prime numbers from 2 to 100.
CLS
FOR I = 2 TO 100
C=0
FOR J = 1 TO I
R = I MOD J
IF R = 0 THEN
C=C+1
ENDIF
NEXT J
IF C=2 THEN
PRINT I;
ENDIF
NEXT I
END