Schoolans.com

Qbasic Programs

rem WAp to find fibonacci series 1 1 2 3 5 8 … upt 13th term
 Declare Sub Ser()
 cls
 call ser
 end
 sub ser
 a = 1
 b = 1
 print a;
 print b;
 for I = 1 to 11 step 1
     c = a + b
     print c;
     a = b
     b = c
 next i
 end sub
*******************************************************************************
Rem WAP to input ten numbers and find greatest among them using array
 rem sub Procedure
 Declare Sub Great(a())
 cls
 DIM a
 for I = 0 to 9 step 1
     input "Enter the number inside array"; a(i)
 next i
 call Great(a())
 end
 sub great(a())
 greatest = 0
 for i = 0 to 9 step 1
     if greatest < a(i) then
         greatest = A(I)
     end if
 next i
 Print "the greatest among ten numbers is "; greatest
 end sub
***********************************************************************************************
Rem WAP to input ten numbers and find greatest among them using array
 rem Function Procedure
 Declare Function Great(a())
 cls
 DIM a
 for I = 0 to 9 step 1
     input "Enter the number inside array"; a(i)
 next i
 print "The greatest number is"; Great(a())
 end
 function  great(a())
 greatest = 0
 for i = 0 to 9 step 1
     if greatest < a(i) then
         greatest = A(I)
     end if
 next i
 GREAT = greatest
 end function
**************************************************************
Rem WAP to print table of 5
 Declare Sub Seri()
 cls
 call Seri
 end
 Sub Seri
 B = 5
 For A = 1 to 10 Step 1
     Print B;"X";A;"="; B*A
 Next A
 end sub
*****************************************************************
REm WAP to find if the inputted number is even or odd using function

Declare Function even_odd$(n)
cls
input "Enter any number "; n
print even_odd$(n)
end

function even_odd$(n)
if n mod 2 =0 then
    EVEN_ODD$ = "The number is even"
    else
    EVEN_ODD$ = "The number is odd"
end if
end function

***********************************************************************

REM WAP to input three number and find greatest among three numbers  function

declare function great$(A,B,C)
cls
input "Enter first number"; A
input "Enter sec number"; B
input "Enter third number"; C
print great$(A,B,C)
end

function great$(A,B,C)
if a>B and A>c then
    ans$ = "The A is greatest"
    elseif b>a and b>c then
    ans$ = "The B is greatest"
    else
    ans$ = "The C is greatest"
end if
GREAT$ = ans$
end function

**********************************************************************
REM WAP to input any number and find +Ve, -ve or 0 function

declare function check$(n)
cls
input "Enter any number to check"; n
print check$(n)
end

function check$(n)
if n=0 then
    ans$ = "The number is zero"
    elseif n>1 then
    ans$ = "The number is +ve"
    else
    ans$ = "The number is -ve"
end if
CHECK$ = ans$
end function

*******************************************************************************
Creating Calculator program in QBASIC Program..
****************************************************
rem WE are creating the calculator program.

declare function  add(a,b)
declare function subt(a,b)
declare function prod(a,b)
declare function division(a,b)
declare function square(a)
cls
print "Which calculation do u want to perform"
input "Addition/1, Subt/2, Product/3, Division/4, Square/5"; N
input "Enter the first number"; A
input "Enter the second number"; B

if n = 1 then
    print "The addition is "; add(a,b)
end if
if n= 2 then
    print "The subtraction is"; subt(a,b)
end if
if n=3 then
    print "The product is"; prod(a,b)
end if
if n=4 then
    print "The the division is "; division(a,b)
end if
if n= 5 then
    print "The square of first number is"; square(a)
end if




function add(a,b)
ADD = A + B
end function

function subt(a,b)
c = A - B
SUBT = c
end function

function prod(a,b)
PROD = A * B
end function

function division(a,b)
DIVISION = A / B
end function

function square(a)
SQUARE = A * A
end function
Use of Global VariableIf
rem WAP to input any number and find if the number is positive or negative.
rem nested if => if inside if is nested if

Declare sub posi_neg(N)
cls
input "Enter any number"; n
Call posi_neg(N)
end

Sub posi_neg(n)
if n>0 then
    Print "the number is positive"
    else
    if n=0 then
        print "The number is zero"
        else
        print "The number is negative"
    end if
end if
end sub
3. Conversion from Decimal number to binary number..
******************************************************8

declare function bin(x)
cls
input "enter decimal num"; y
print "The equivalent is "; bin(y)
end
function bin(x)
while x<>0
    r = X MOD 2
    s$ = str$(r) + s$
    X = X \ 2
wend
d = val(s$)
BIN = d
end function
4. WAP to find the area of circle . [Hint : A = PI * R * R ]
Declare function area(r)
 cls
 Input  "  Enter the radius of circle";R
 Print area(r)
 END

Function area(r) 
   PI = 22/7
   A = PI * R * R
   area = A 
END Function

5.Declare SUB area(r)
 cls
 Input "Enter the radius of circle"; R
 CALL area(R)
 END
SUB area(r)
  PI = 22/7
  A = PI * R * R
  Print  "THE area  of circle is "; A
end sub

A) Conditional Statement in QBASIC
 i. if .... end if 
ii. if .... else .... end if 
iii. multiple if 

i. if... end if 

       cls 
       input "Enter your roll no "; R 
       if  R = 5 then 
             Print " Congs your roll no is 5!!!"
       
       else 
            Print "Try AGAin "

       end if 


iii. Multiple if 
	
Syntax: 
	if (condition) then
	

	elseif (condition) then 
	

	elseif (condition) then 
	

	elseif (condtion) then 

	
	else 

end if 

 587 total views,  2 views today