Programming in QBASIC
Programming in QBASIC
1) To add two numbers
CLS
rem let the two numbers be 2 and 3
A = 2
B = 3
PRINT "The sum of"; A; "and"; B; "is"; A + B
END
2) To subtract two numbers
CLS
rem let the two numbers be 5 and 2
A = 5
B = 2
PRINT "The subtraction of"; A; "and"; B; "is"; A - B
END
3) To Multiply two numbers
cls
rem let the two numbers be 5 and 2
A = 5
B = 2
Print "The Multiplication of"; A; "and"; B; "is"; A*B
END
4) To Divide two numbers
CLS
REM let the two numbers be 4 and 16
A = 4
B = 16
Print "The Division of"; A; "and"; B; "is"; B/A
END
5) To ask person name, age. If the person age is greater than 18, display his name telling that he is eligible to vote.
CLS
INPUT " Enter the name "; Name$
PRINT " Your name is "; Name$
INPUT " Enter your age "; A
IF A >= 18 THEN
PRINT Name$; " is able to vote "
ELSE
PRINT Name$; " can't vote "
END IF
END
6) To print all even numbers 1 to 100
CLS
FOR i = 1 TO 50
PRINT i * 2
NEXT i
END
7) To display -:
CLS
PRINT "1"
PRINT "10"
PRINT "100"
PRINT "1000"
PRINT "10000"
END
8) WAP to make the Multiplication table of any number
CLS
INPUT "Enter a Number: ", n
FOR i = 1 TO 10
PRINT n; " * "; i; " = "; n * i
NEXT i
END
9) WAP to display user name, phone, age, and gender and ask a condition if user wants to insert another data. If user type "yes" then again take input and display else end the program.
CLS
here:
INPUT " Enter your name "; Name$
INPUT " Enter your Age "; Age$
INPUT " Enter your Phone Number "; Number$
INPUT " What is your Gender "; Gender$
INPUT " Do you want to Enter another data "; A$
IF A$ = "yes" THEN
GOTO here
END IF
END
10) WAP to display whether the given character is vowel or not
CLS
INPUT "Enter a Letter:"; V$
IF V$ = "a" OR V$ = "e" OR V$ = "i" OR V$ = "o" OR V$ = "u" THEN
PRINT "It is Vowel Letter";
ELSE
PRINT "It is not Vowel Letter";
END IF
END
11) WAP to Create a below program to withdraw cash:
CLS
PRINT " 1) 1000 "
PRINT " 2) 2000 "
PRINT " 3) 5000 "
PRINT " 4) 10000 "
PRINT " 5) 15000 "
PRINT " 6) 25000 "
INPUT " Enter your Number "; t$
IF t$ = "1" THEN
PRINT " We have got your transaction successfully, your amount is 1000 ";
ELSE
PRINT " ";
END IF
IF t$ = "2" THEN
PRINT " We have got your transaction successfully, your amount is 2000 ";
ELSE
PRINT " ";
END IF
IF t$ = "3" THEN
PRINT " We have got your transaction successfully, your amount is 5000 ";
ELSE
PRINT " ";
END IF
IF t$ = "4" THEN
PRINT " We have got your transaction successfully, your amount is 10000 ";
ELSE
PRINT " ";
END IF
IF t$ = "5" THEN
PRINT " We have got your transaction successfully, your amount is 15000 ";
ELSE
PRINT " ";
END IF
IF t$ = "6" THEN
PRINT " We have got your transaction successfully, your amount is 25000 "
ELSE
PRINT " ";
END IF
END
12) WAP to find the maximum value among three numbers. Numbers using read.... data for reading those three numbers.
Cls
Read a, b, c:
Data 30,40,60:
If a > b And a > c Then
Print a; "is maximum value among three numbers!"
ElseIf b > a And b > c Then
Print b; "is maximum value among three numbers!"
Else
Print c; "is maximum value among three numbers!"
End If
End
13) WAP to give input from 1 to 5 and do operation according to given input.
Cls
Print " 1) 1000 "
Print " 2) 2000 "
Print " 3) 5000 "
Print " 4) 10000 "
Print " 5) 15000 "
Print " 6) 25000 "
Input " Enter your Number "; t$
Select Case t$
Case "1": Print " We have got your transaction successfully, your amount is 1000 "
Case "2": Print " We have got your transaction successfully, your amount is 2000 "
Case "3": Print " We have got your transaction successfully, your amount is 5000 "
Case "4": Print " We have got your transaction successfully, your amount is 10000 "
Case "5": Print " We have got your transaction successfully, your amount is 15000 "
Case "6": Print " We have got your transaction successfully, your amount is 25000 "
Case Else:
Print " The Number you have enter is not there available "
End Select
End
14) Rem WAP to print the multiplication table user input number.
Cls
Input "Enter a Number to Multiply: ", a
For i = 1 To 10 Step 1
Print a; " * "; i; " = "; a * i
Next i
End
15) WAP to find the number whether it is composite or prime number.
Cls
Input "Enter any Number to Know it is composite or Prime Number"; A
B = 0
For I = 1 To A
If A Mod I = 0 Then B = B + 1
Next I
If B = 2 Then
Print A; "Is a Composite Numbe"
Else
Print A; "Is a Prime Number"
End If
End
16) Rem WAP to find out HCF and LCM from two given number.
Cls
Here: Input " Enter a Number to know whether it is LCM or HCF "; x, y
A = x
B = y
While A > 0
r = B Mod A
B = A
A = r
Wend
l = x * y / B
Print " LCM = "; l
Print " HCF = "; B
GoTo Here
End
Comments
Post a Comment