Professional Documents
Culture Documents
50 PRINT Area=;AREA
60 END
Q9. Write a program to calculate area and circumference of a circle. The
program should get the radius of circle from user and display result.
10 CLS
20 INPUT Enter radius:;R
30 AREA=3.14*R^2
40 CIR=2*3.14*R
50 PRINT Area of circle=;AREA
60 PRINT Circumference of circle=;CIR
70 END
Q10. Write a program to print first ten odd numbers using WHILEWEND
loop.
10 CL
20 N=1
30 WHILE N<=19
40 PRINT N
50 N=N+2
60 WEND
70 END
Q11. Write a program in BASIC to print the sum of squares of first five
even numbers using FORNEXT loop.
10 CLS
20 SUM=0
30 FOR N=2 TO 10 STEP2
40 SUM=SUM+N^2
50 NEXT N
60 PRINT Sum= ;SUM
70 END
Q12. Write a program to find the largest of two numbers. The program
should get the numbers from user.
10 CLS
20 INPUT Enter first number:,A
30 INPUT Enter second number:,B
40 IF A>B THEN PRINT A ELSE PRINT B
50 END
Q13. Write a program to print the table of a given number. The program
should get the number from user.
10 CLS
20 INPUT Enter table number:,T
30 FOR N=1 TO 10
40 PRINT T; *;N; = T*N
50 NEXT N
60 END
Q14. Write a program that should accept obtained marks of a student in
an examination. It should then calculate the percentage and assign a
grade to the student.
10 CLS
20 INPUT Enter marks in Math:;math
30 INPUT Enter marks in English:;eng
40 INPUT Enter marks in Urdu:;urdu
50 INPUT Enter marks in Physics:;phy
60 INPUT Enter marks in Chemistry:;chem
70 INPUT Enter marks in Computer:;comp
80 total=math+eng+urdu+phy+chem+comp
90 per=TOTAL*100/700
100 IF per>=80 THEN g $ = A1 : GOTO 150
110 IF per>=70 THEN g $ = A : GOTO 150
120 IF per>=60 THEN g $ = B : GOTO 150
110 NEXT N
120 END
Q14. Write a program to print a list of odd numbers from given data. 6, 42,
4, 77, 32, 9, 21, 22, 8, 45, 15, 46
10 CLS
20 DIM ARR (11)
30 FOR N=0 TO 11
40 READ ARR (N)
50 NEXT N
60 DATA 6, 42, 77, 32, 9, 21, 22, 8, 45, 15, 46
70 FOR N=0 TO 11
80 IF ARR (N) MOD 2<>0 THEN PRINT ARR (N)
90 NEXT N
100 END
Q15. Write a program that reads an array N with 20 numbers and find the
product of the elements of array.
10 CLS
20 PRODUCT=1
30 DIM N (19)
40 FOR J=0 TO 19
50 INPUT Enter a number:, N (J)
60 PRODUCT=PRODUCT*N (J)
70 NEXT J
80 PRINT Product=; PRODUCT
90 END
Q16. Write a program that read an array Z having 12 numbers given by
user then print the sum and average of all array elements.
10 CLS
20 SUM=0
30 DIM Z(11)
40 FOR N=0 TO 11
50 INPUT Enter a number:, Z(N)
60 SUM=SUM+Z(N)
70 NEXT N
80 PRINT Sum=;SUM
90 PRINT Average=;SUM/12
Q18. Write a program to sort a list of 20 names in descending order?
10 CLS
20 DIM ARR $(19)
30 FOR N=0 TO 19
40 INPUT Enter name:,ARR $(N)
50 NEXT N
60 FOR I=0 TO 19
70 FOR J=I+1 TO 19
80 IF ARR $(I)<ARR $(J) THEN TEMP$=ARR $(I): ARR $(I)=ARR $(J): ARR $(J)=TEMP$
90 NEXT J
100 NEXT I
110 PRINT Names in descending order:
120 FOR N=0 TO 19
130 PRINT ARR $(N)
140 NEXT N
150 END
CH5 SUB PROGRAM AND FILE HANDLING
Q11. Write a program to get full name of any person and return the
number of characters in his first name.
10 CLS
20 INPUT Enter name:;Nam$
30 ch=INSTR(I, Nam$, )
40 PRINT Total chahracters in first part of name: ch-1
50 END
Q12. Write a program that print ASCII chahracters from 1 to 255.
10 CLS
20 FORm=1 TO 255
30 PRINT CHR$(M)
40 END
Q13. Write a program that is used for conservation of temperature from
Celsius scale to Fahrenheit scale with the help of DEF FN function.
10 CLS
20 DEF FN convert (t)=9/5*t+32
30 INPUT Enter temperature in centigrade:;t
40 PRINT Temperature Temperature in Fahrenheit=;FN
50 END
Q14. Write a program to print and calculate the following by using userdefined function. Combination=n!/k!(n-k)!
10 CLS
20 DEF FN comb (n, k)=n/k (n-k)
30 OPEN My Phone.txt FOR OUTPUT AS#1
40 WHILE M$= Y OR M$= Y
50 INPUT Enter name:, N$
60 INPUT Enter phone:, P$
70 INPUT Enter address:, A$
80 WRITE # 1, N$, P$, A$
90 INPUT Do you want to enter more records! [y/n];M$
100 WEND
110 CLOSE#1
120 END
CH6 GRAPHICS IN BASIC
Q9. Find the errors
(a)
LINE (140,100)-(300, 100), 2, BF,4
The above program statement uses hyphen instead of comma in second coordinate
(300-100).
(b)
10 Screen
20 COLOR 1, 2
30 DRAW U10R10 D10L10
The above program will display illegal function call
(c)
10 Screen 1
20 A=20
30 DRAW U=A R=A D=A L=A
The line 30 of above program is wrong.
Q11. Write a program to draw a star.
10 CLS
20 SCREEN 2
30 LINE (50, 50)-(100, 50)
40 LINE (100, 50)-(130, 30)
50 LINE (130, 30)-(160, 50)
60 LINE (160, 50)-(210, 50)
70 LINE (210, 50)-(180, 70)
80 LINE (180, 70)-(200, 90)
90 LINE (200, 90)-(130, 75)
100 LINE (130, 75)-(70, 90)
110 LINE (70, 90)-(100, 70)
120 LINE (100, 70)-(50, 50)
Q15. Write a program to produce five concentric circles of different radii.
10 CLS
20 SCREEN2
30 FOR N= 10 TO 50 STEP 5
40 CIRCLE (100, 50), N
50 NEXT N
60 END
Q16. Write a program to draw a parallelogram by using DRAW statement.
10 CLS
20 SCREEN2
30 PSET (100, 100)
40 DRAW E20 R100 G20 L100
50 END