Computer Program Qbasic
Computer Program Qbasic
Cls
Call Prim
End
Sub Prim ()
For N = 2 To 10
c=0
For i = 1 To N
If N Mod i = 0 Then
c=c+1
End If
Next i
If c = 2 Then
Print N
End If
Next N
End Sub
2. To display the first 10 multiples of 7
Cls
Call Mul
End
Sub Mul ()
a=7
For i = 1 To 10
b=a*i
Print b
Next i
End Sub
3. To display multiplication table of 5
Cls
Call Multi
End
Sub Multi ()
For i = 1 To 10
Next i
End Sub
4. To calculate the sum of numbers sequentially
Cls
Call CalculateSum
End
Sub CalculateSum ()
sum = 0
For i = 1 To n
Next i
End Sub
5. To print largest number in sequence
Cls
Call FindLargestNumber
End
Sub FindLargestNumber ()
largest = 0
For i = 1 To n
largest = term
End If
Next i
End Sub
6. To print Fibonacci Series
CLS
CALL FibonacciSeries()
END
SUB FibonacciSeries()
a=0
b=1
FOR i = 1 TO n
PRINT a;
c=a+b
a=b
b=c
NEXT i
END SUB
7. To demonstrate while loop
Cls
Call CalculateFactorial
End
Sub CalculateFactorial ()
If n < 0 Then
Else
fact = 1
While n > 0
fact = fact * n
n=n-1
Wend
End If
End Sub
8. To demonstrate for loop in qbasic
Rem Program to demonstrate FOR loop using SUB procedure to display numbers
Cls
Call DisplayNumbers
End
Sub DisplayNumbers ()
For i = 1 To limit
Print i
Next i
End Sub
9. Display even numbers using do while loop
CLS
CALL DisplayEvenNumbers()
END
SUB DisplayEvenNumbers()
num = 1
DO
PRINT num
END IF
num = num + 1
END SUB