0% found this document useful (0 votes)
2 views16 pages

Qbasic Programs

The document contains a series of programming tasks written in BASIC language, each demonstrating different functionalities such as string manipulation, mathematical operations, and conditional checks. It includes programs for reversing strings, checking for palindromes, calculating sums and products of digits, determining prime numbers, and various geometric calculations. The tasks serve as exercises for learning programming concepts and logic.

Uploaded by

Niruta Uprety
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Qbasic Programs

The document contains a series of programming tasks written in BASIC language, each demonstrating different functionalities such as string manipulation, mathematical operations, and conditional checks. It includes programs for reversing strings, checking for palindromes, calculating sums and products of digits, determining prime numbers, and various geometric calculations. The tasks serve as exercises for learning programming concepts and logic.

Uploaded by

Niruta Uprety
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

WAP to input any string and reverse it.

CLS
INPUT "ENTER ANY STRING"; S$

FOR I = LEN(S$) TO 1 STEP -1


B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
PRINT "REVERSED STRING IS "; W$
END

WAP to input any string and check whether the given string
is palindrome or not.
CLS
INPUT "ENTER ANY STRING"; S$
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
IF S$ = W$ THEN
PRINT S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
END
WAP to input number and find sum of digits.
CLS
INPUT "ENTER ANY NUMBER"; N
S=0
WHILE N < > 0
R = N MOD 10
S=S+R
N = N \ 10
WEND
PRINT "SUM OF DIGITS"; S
END

WAP to input number and find product of digits.


CLS
INPUT "ENTER ANY NUMBER"; N
P=1
WHILE N < > 0
R = N MOD 10
P=P*R
N = N \ 10
WEND
PRINT "PRODUCT OF DIGITS"; P
END
WAP to input any number and display the factors.
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "FACTORS OF"; N; "=";
FOR I = 1 TO N
IF N MOD I = 0 THEN PRINT I;
NEXT I
END

WAP to input number and check whether the given no. is


prime or composite.
CLS
INPUT "ENTER ANY NUMBER"; N
C=0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT N; "IS PRIME NUMBER"
ELSE
PRINT N; "IS COMPOSITE NUMBER"
END IF
END
WAP TO ENTER ANY DIGIT AND DISPLAY ITS
REVERSED FORM.
CLS
INPUT "ENTER ANY NUMBER"; N
S=0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
PRINT "REVERSED DIGITS="; S
END

WAP to enter any two numbers and display the greater one.
CLS
INPUT “ENTER ANY TWO NUMBERS”; A, B
IF A > B THEN
PRINT A; “IS GREATER”
ELSE
PRINT B; “IS GREATER”
END IF
END
WAP to enter any two numbers and display the smaller one.
CLS
INPUT “ENTER ANY TWO NUMBERS”; A, B
IF A < B THEN
PRINT A; “IS SMALLER”
ELSE
PRINT B; “IS SMALLER”
END IF
END

WAP to enter any three numbers and display the greatest


one.
CLS
INPUT “ENTER ANY THREE NUMBERS”; A, B, C
IF A > B AND A > C THEN
PRINT A; “IS GREATEST”
ELSEIF B > A AND B > C THEN
PRINT B; “IS GREATEST”
ELSE
PRINT C; “IS GREATEST”
END IF
END
WAP to enter any three numbers and display the smallest
one.
CLS
INPUT “ENTER ANY THREE NUMBERS”; A, B, C
IF A < B AND A < C THEN
PRINT A; “IS SMALLEST”
ELSEIF B < A AND B < C THEN
PRINT B; “IS SMALLEST”
ELSE
PRINT C; “IS SMALLEST”
END IF : END

WAP to input any number and check whether the given no.
is divisible by 5 or not.
CLS
INPUT “ENTER ANY NUMBER”; N
IF N MOD 5 = 0 THEN
PRINT N; "IS DIVISIBLE BY 5”
ELSE
PRINT N; "IS NOT DIVISIBLE BY 5”
END IF
END
WAP to input any number and check whether the given no.
is divisible by 3 and 7 or not.
CLS
INPUT “ENTER ANY NUMBER”; N
IF N MOD 3 = 0 AND N MOD 7 = 0 THEN
PRINT N; "IS COMPLETELY DIVISIBLE BY 3 AND 7”
ELSE
PRINT N; "IS NOT COMPLETELY DIVISIBLE BY 3 AND 7”
END IF
END

WAP to input any number and check whether the given no. is
positive, negative or zero.
CLS
INPUT “ENTER ANY NUMBER”; N
IF N > 0 THEN
PRINT N; "IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; "IS NEGATIVE NUMBER”
ELSE
PRINT N; "IS ZERO”
END IF
END
WAP to input a year and display whether that year is a leap
year or not. [divisible by 4 but not 100]
CLS
INPUT “ENTER YEAR”; Y
IF Y MOD 4 = 0 AND Y MOD 100 <> 0 OR Y MOD 400 = 0
THEN
PRINT Y; "IS LEAP YEAR”
ELSE
PRINT Y; "IS NOT LEAP YEAR”
END IF
END

WAP to input any number and display whether it is odd or


even.
CLS
INPUT “ENTER ANY NUMBER”; N
IF N MOD 2 = 0 THEN
PRINT N; “IS EVEN NUMBER”
ELSE
PRINT N; “IS ODD NUMBER”
END IF
END
WAP to input a mark in a subject of a student and check if
the student is pass or nor. [Pass Mark >=40]
CLS
INPUT “ENTER MARKS”; M
IF M >= 40 THEN
PRINT “YOU ARE PASS”
ELSE
PRINT “ YOU ARE FAIL”
END IF
END

WAP to the age of a person and find out whether the person
is eligible to drive or not. [age >=16]
CLS
INPUT “ENTER YOUR AGE”; A
IF A >= 16 THEN
PRINT “YOU ARE ELIGIBLE TO DRIVE”
ELSE
PRINT “ YOU ARE NOT ELIGIBLE TO DRIVE”
END IF
END
WAP to the age of a person and find out whether the person
is eligible to vote or not. [age >=18]
CLS
INPUT “ENTER YOUR AGE”; A
IF A >= 18 THEN
PRINT “YOU ARE ELIGIBLE TO VOTE”
ELSE
PRINT “ YOU ARE NOT ELIGIBLE TO VOTE”
END IF
END

WAP to Calculate distance.[S=UT+1/2(AT2)]


CLS
INPUT “ENTER INITIAL VELOCITY”; U
INPUT “ENTER TIME”; T
INPUT “ENTER ACCELARATION”; A
S=U*T+1/2*A*T^2
PRINT “DISTANCE TRAVELLED = “; S
END
WAP to accept temperature in Fahrenheit from user and
convert into the Celsius.
CLS
INPUT “ENTER TEMPERATURE IN FARENHEIT”; F
C = (F – 32) * (5 / 9)
PRINT “TEMPERATURE IN CELCIUS=”; C
END

WAP to to accept temperature in Celcius from user and


convert into the Farenheit.
CLS
INPUT “ENTER TEMPERATURE IN CELCIUS”; C
F = C * (9 / 5) + 32
PRINT “TEMPERATURE IN FARENHEIT=”; F
END

WAP to calculate profit.


CLS
INPUT “ENTER COST PRICE”; CP
INPUT “ENTER SELLING PRICE”; SP
P = SP - CP
PRINT “PROFIT AMOUNT=”; P
END
WAP to calculate loss.
CLS
INPUT “ENTER COST PRICE”; CP
INPUT “ENTER SELLING PRICE”; SP
L = CP - SP
PRINT “LOSS AMOUNT=”; L
END

WAP to display simple interest.


CLS
INPUT “ENTER PRINCIPAL”; P
INPUT “ENTER TIME”; T
INPUT “ENTER RATE”;R
I = P* T * R / 100
PRINT “SIMPLE INTEREST =”; I
END

WAP to input principal, rate, time and display total amount.


CLS
INPUT “ENTER PRINCIPAL”; P
INPUT “ENTER TIME”; T
INPUT “ENTER RATE”;R
I = P* T * R / 100
A=P+I
PRINT “TOTAL AMOUNT=”; A
END
WAP to input principal, rate, time and display simple interest
and total amount.
CLS
INPUT “ENTER PRINCIPAL”; P
INPUT “ENTER TIME”; T
INPUT “ENTER RATE”;R
I = P* T * R / 100
A=P+I
PRINT “SIMPLE INTEREST=”;I
PRINT “TOTAL AMOUNT=”; A
END

WAP to display total surface area of sphere.


CLS
INPUT “ENTER RADIUS ”; R
A= 4 * 3.14 * R ^ 2
PRINT “TOTAL SURFACE AREA OF SPHERE “; A
END

WAP to display volume of sphere.


CLS
INPUT “ENTER RADIUS ”; R
V = (4 / 3) * 3.14 * R ^ 3
PRINT “VOLUME OF SPHERE ”; V
END
WAP to display volume of cylinder.
CLS
INPUT “ENTER RADIUS ”; R
INPUT “ENTER HEIGHT”; H
V = 3.14 * R ^ 2 * H
PRINT “VOLUME OF CYLINDER ”; V
END

WAP to display area of 4 walls.


CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
A = 2 * H * (L + B)
PRINT “AREA OF FOUR WALLS“; A
END

WAP to display area of triangle.


CLS
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
A = 1 / 2 * (B * H)
PRINT “AREA OF TRIANGLE “; A
END
WAP to display area of rectangle.
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
A=L*B
PRINT “AREA OF RECTANGLE ”; A
END

WAP to display area of circle.


CLS
INPUT “ENTER RADIUS”; R
A = 3.14 * R ^ 2
PRINT “AREA OF CIRCLE ”; A
END

WAP to display perimeter of rectangle.


CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
P = 2 * (L + B)
PRINT “PERIMETER OF RECTANGLE ”; P
END
WAP to display square of an input number.
CLS
INPUT “ENTER ANY NUMBER”; N
S=N^2
PRINT “SQUARE OF NUMBER ”; S
END

WAP to display square root of an input number.


CLS
INPUT “ENTER ANY NUMBER”; N
S = N ^ (1 / 2)
PRINT “SQUARE ROOT OF NUMBER ”; S
END

WAP to display cube root of an input number.


CLS
INPUT “ENTER ANY NUMBER”; N
C = N ^ (1 / 3)
PRINT “CUBE ROOT OF NUMBER ”; C
END

WAP to display sum of square of any two input numbers.


CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S=A^2+B^2
PRINT “SUM OF SQUARE OF TWO NUMBERS ”; S
END

You might also like