QBASIC PROGRAMMINGS
1)
Using FUNCTION procedure
write a program to check whether the given number is armstrong or not.
Ø DECLARE FUNCTION CHECK(N)
CLS
INPUT “Enter any number”; N
A=N
ARM=CHECK (N)
IF A=ARM THEN
PRINT “Armstrong number”
ELSE
PRINT “Not Armstrong number”
END IF
END
FUNCTION CHECK (N)
S=0
WHILE N<>0
R=N MOD 10
S=S+R^3
N=N\10
WEND
CHECK=S
END FUNCTION
2)
Using SUB procedure write
a program to check whether the given number is palindrome or not.
Ø DECLARE SUB CHECK(N)
CLS
INPUT “Enter any number”; N
CALL CHECK (N)
END
SUB CHECK (N)
S=0
A=N
WHILE N<>0
R=N MOD 10
S=S*10+R
N=N\10
WEND
IF A=S THEN
PRINT “Palindrome number”
ELSE
PRINT “Not palindrome number”
END IF
END SUB
3)
Using SUB procedure write
a program to display factors of a given number.
Ø DECLARE SUB FACTOR(N)
CLS
INPUT “Enter any number”; N
CALL FACTOR (N)
END
SUB FACTOR (N)
PRINT “The factors are”
FOR I=1 TO N
IF N MOD I = 0 THEN PRINT I,
NEXT I
END SUB
4)
Using FUNCTION procedure
write a program to display factorial of a given number.
Ø DECLARE FUNCTION FACT(N)
CLS
INPUT “Enter any number”; N
PRINT “The factorial is”; FACT (N)
END
FUNCTION FACT (N)
F=1
FOR I=1 TO N
F=F*I
NEXT I
FACT=F
END FUNCTION
5)
Using SUB procedure write
a program to reverse the given digit.
Ø DECLARE SUB REVERSE (N)
CLS
INPUT “ENTER ANY DIGIT”; N
CALL REVERSE (N)
END
SUB REVERSE (N)
REV=0
WHILE N<>0
R=N MOD 10
REV=REV*10+R
N=N\10
WEND
PRINT “The reversed digit is”; REV
END SUB
6)
Using FUNCTION procedure
write a program to check whether the given number is prime or composite.
Ø DECLARE FUNCTIONCHECK (N)
CLS
INPUT “Enter any number”; N
P=CHECK (N)
IF P=2 THEN
PRINT “Prime number”
ELSE
PRINT “Composite number”
END IF
END
FUNCTION CHECK (N)
C=0
FORI=1 TO N
IF N MOD I=0 THEN C=C+1
NEXT I
CHECK=C
END FUNCTION
7)
Using SUB procedure write
a program to find the sum of given digits.
Ø DECLARE SUB SUM (N)
CLS
INPUT “Enter any digit”; N
CALL SUM (N)
END
SUB SUM (N)
S=0
WHILE N<>0
R=N MOD10
S=S+R
N=N\10
WEND
PRINT “Sum of digits=”; s
END SUB
8)
Using FUNCTION procedure
write a program to count total number of odd digits in a given digit.
Ø DECLARE FUNCTION COUNT
(N)
CLS
INPUT “Enter any digit”; N
PRINT “Total number of odd digits is”; COUNT (N)
END
FUNCTION COUNT (N)
C=0
WHILE N<>0
R=N MOD 10
IF R MOD 2 =1 THEN C=C+1
N=N\10
WEND
COUNT=C
END FUNCTION
9)
Using SUB procedure write
a program to display only even numbers from the input.
Ø DECLARE SUB EVEN (N)
CLS
INPUT “Enter any number”; N
CALL EVEN (N)
END
SUB EVEN (N)
E=O
WHILE N<>0
R=N MOD 10
IF R MOD 2 = 0 THEN PRINT E
N=N\10
WEND
PRINT “Even numbers are”; E
END SUB
10)Using function procedure write a program to find the HCFand LCM of a given number.
DECLARE FUNCTION HCFLCM(A,B)
CLS
INPUT"ENTER ANY TEO NUMBER";A,B
PRINT"LCM=";HCFLCM(A,B)
END
FUNCTION HCFLCM(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
HCFLCM=L
END FUNCTION
10)Using function procedure write a program to find the HCFand LCM of a given number.
DECLARE FUNCTION HCFLCM(A,B)
CLS
INPUT"ENTER ANY TEO NUMBER";A,B
PRINT"LCM=";HCFLCM(A,B)
END
FUNCTION HCFLCM(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
HCFLCM=L
END FUNCTION
Last Question number program is wrong, the correct program is
ReplyDeleteDECLARE SUB EVEN (N)
CLS
INPUT “Enter any number”; N
CALL EVEN (N)
END
SUB EVEN (N)
WHILE N<>0
R=N MOD 10
IF R MOD 2 = 0 THEN PRINT R
N=N\10
WEND
END SUB
This comment has been removed by the author.
Deletecan u write a program to make crime recording system that can record name ,age,nationality and other and should have add option, display option,delete option
ReplyDeleteHow to Make Money in Soccer - Work-to-Earn
ReplyDeleteLearn how to make 바카라 사이트 money by becoming an independent งานออนไลน์ soccer player. Learn how to make money at top sportsbooks in 1xbet the world.