Sei sulla pagina 1di 10

Computer Science Programs

Ch1 PROBLEM SOLVING


Q9: Write an algorithm to calculate the area of circle the radius is given.
Area= 3.14*r*r
10. Start
20. Input radius in r
30. Area= 3.14*r*r
40. Print area
50. End
Q10 (x): Write an algorithm to calculate the distance covered by a car
moving at an average speed of v ms/s in t. The algorithm should input
average speed and time. (Hint s=VT where s is distance)
10. Start
20. Input average speed in v
30. Input time in T
40. S=v*t
50. Print s
60. End
CH2 DATA TYPES ASSIGNMENT AND INPUT/OUTPUT STATEMENTS
Q10 (ix): Write a program that asks for name, roll number, class section
and marks obtained in different subjects of a student of class 10. The
program should calculate and display total marks and percentage of
student. Hint: use INPUT statement to get data from user, total marks are
850.
10. CLS
20. INPUT Enter name:; N$
30. INPUT Enter roll no:;roll
40. INPUT Enter class:;Class$
50. INPUT Enter section:; Sec $
60. INPUT Enter marks in Math:;math
70. INPUT Enter marks in English:;eng

80. INPUT Enter marks in Urdu:;urdu


90. INPUT Enter marks in Physics:;phy
100. INPUT Enter marks in Chemistry:;che
110. INPUT Enter marks in Computer:;comp
120. INPUT Enter marks in Islamiat:;islam
130. INPUT Enter marks in Pak Studies:;ps
140. total= math+eng+urdu+phy+chem+comp+islam+ps
150. per= TOTAL*100/850
160. PRINT Name:;N$
170. PRINT Roll No:;roll
180. PRINT Class:;class$
190. PRINT section:;sec$
200. PRINT Total marks:;total
210. PRINT Percentage:;per
220. END
Q10 (x): Write a program to calculate the distance covered by a car
moving at an average speed of vms-1 in time t. The program should input
average speed and time.
10. CLS
20. INPUT Enter average speed:;v
30. INPUT Enter time:;t
40. S=v*t
50. PRINT Distance covered:;s
60. END
Q11: Write a program to calculate the volume of cylinder. The program
should get the values from height to cylinder and cylinder and the radius
of its base from the user through INPUT statement. [Hint:
volume=3.14*r*r*h]
10 CLS
20 INPUT Enter radius of cylinder:;r

30 INPUT Enter height of cylinder:;h


40 v=3.14*r*r*h
50 PRINT Volume of cylinder:;v
60 END
Q12. Write a program to compute the square of a give number. The
program should get the number from user through INPUT statement.
10 CLS
20 INPUT Enter a number:;n
30 s=n*n
40 PRINT Square:;s
50 END
Q13: Write a program to calculate and print the sum and average of three
numbers using LET statement.
10 CLS
20 LET A=10
30 LET B=20
40 LET C=30
50 LET sum=A+B+C
60 LET AVG=SUM/3
70 PRINT Sum=;SUM
80 PRINT Average=;AVG
90 END
CH3 CONTROL STRUCTURES
Q8. Write a program to calculate the area of triangle. The program should
get the values for base and altitude of the triangle from the user and
display the result.
10 CLS
20 INPUT Enter base:;BASE
30 INPUT Enter altitude:;AL
40 AREA=1/2*BASE*AL

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

130 IF per>=50 THEN g $ = C : GOTO 150


140 IF per>=40 THEN g $ = D ELSE g $ = F
150 PRINT Percentage : ; per
160 PRINT Grade :; g $
170 END
CH4 ARRAYS
Q10. Write a program in BASIC to enter integer type data into an array and
then to print the value s in reverse order.
10 CLS
20 DIM ARR (4)
30 FOR N= 0 TO 4
40 INPUT Enter a number : , ARR (N)
50 NEXT N
60 PRINT Array in reverse order :
70 FOR N= 4 TO 0 STEP 1
80 PRINT ARR (N)
90 NEXT N
100 END
Q13. Write a program to sum array A elements and B elements.
10 CLS
20 DIM A (2), B (2)
30 FOR N=0 TO 2
40 INPUT Enter number in Array A:, A (N)
50 NEXT N
60 FOR N=0 TO 2
70 INPUT Enter number in Array B:, B (N)
80 NEXT N
90 FOR N=0 TO 2
100 PRINT A (N); +; B (N); =; A (N) +B (N)

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

Potrebbero piacerti anche