0% found this document useful (0 votes)
10 views

Computer Program Qbasic

The document contains examples of using different loops like FOR, WHILE, and DO WHILE loops in the QBasic programming language. The examples include finding prime numbers, displaying multiples, multiplication tables, calculating sums, finding largest numbers, Fibonacci series, factorials, and displaying even numbers.

Uploaded by

shresthaaditya38
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)
10 views

Computer Program Qbasic

The document contains examples of using different loops like FOR, WHILE, and DO WHILE loops in the QBasic programming language. The examples include finding prime numbers, displaying multiples, multiplication tables, calculating sums, finding largest numbers, Fibonacci series, factorials, and displaying even numbers.

Uploaded by

shresthaaditya38
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
You are on page 1/ 9

1.

To print prime number from 1 to 10

REM to find and print prime numbers between 1 and 10.

DECLARE SUB Prim()

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

Rem To display the first 10 multiples of 7

DECLARE SUB Mul()

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

Rem To display the multiplication table of 5 up to the 10th term

DECLARE SUB Multi()

Cls

Call Multi

End

Sub Multi ()

For i = 1 To 10

Print "5 x "; i; " = "; 5 * i

Next i

End Sub
4. To calculate the sum of numbers sequentially

Rem Program to calculate the sum of numbers sequentially

DECLARE SUB CalculateSum()

Cls

Call CalculateSum

End

Sub CalculateSum ()

Input "Enter the number of terms: ", n

sum = 0

For i = 1 To n

Input "Enter values : ", term

sum = sum + term

Next i

Print "The sum of the numbers is: "; sum

End Sub
5. To print largest number in sequence

Rem Program to find the largest number sequentially

DECLARE SUB FindLargestNumber()

Cls

Call FindLargestNumber

End

Sub FindLargestNumber ()

Input "Enter the number of terms: ", n

largest = 0

For i = 1 To n

Input "Enter values upto the term : ", term

If term > largest Then

largest = term

End If

Next i

Print "The largest number is: "; largest

End Sub
6. To print Fibonacci Series

REM Program to print the Fibonacci series sequentially

DECLARE SUB FibonacciSeries()

CLS

CALL FibonacciSeries()

END

SUB FibonacciSeries()

INPUT "Enter the number of terms in the Fibonacci series: ", n

a=0

b=1

PRINT "The Fibonacci series:"

FOR i = 1 TO n

PRINT a;

c=a+b

a=b

b=c

NEXT i

END SUB
7. To demonstrate while loop

Rem Program to demonstrate WHILE loop to calculate factorial of a number

DECLARE SUB CalculateFactorial()

Cls

Call CalculateFactorial

End

Sub CalculateFactorial ()

Input "Enter a positive integer: ", n

If n < 0 Then

Print "Factorial is not defined for negative numbers!"

Else

fact = 1

While n > 0

fact = fact * n

n=n-1

Wend

Print "Factorial is: "; fact

End If

End Sub
8. To demonstrate for loop in qbasic

Rem Program to demonstrate FOR loop using SUB procedure to display numbers

DECLARE SUB DisplayNumbers()

Cls

Call DisplayNumbers

End

Sub DisplayNumbers ()

Input "Enter the limit: ", limit

For i = 1 To limit

Print i

Next i

End Sub
9. Display even numbers using do while loop

REM Program to demonstrate DO...LOOP WHILE loop using SUB procedure

DECLARE SUB DisplayEvenNumbers()

CLS

CALL DisplayEvenNumbers()

END

SUB DisplayEvenNumbers()

INPUT "Enter the limit: ", limit

num = 1

DO

IF num MOD 2 = 0 THEN

PRINT num

END IF

num = num + 1

LOOP WHILE num <= limit

END SUB

You might also like