Wednesday 25 March 2020

QBasic Program

1.Wap a program to convert nepali currency to American Currency where 1$ =Rs 95

DECLARE FUNCTION am(nc)
CLS
input "nepali currency=";nc
print "American currency=";am(nc)
end
function am(NC)
am=NC/95
end function

2. Wap to declare a user-defined function to reverse a string.

DECLARE FUNCTION  a$(n$)
cls
input "enter any word";n$
print "reverse of string"a$(n$)
end
function a$(n$)
for i=len(n$) to 1 step -1
b$=b$+mid$(n$,i,1)
next i
a$=b$
end function

3. Wap to calculate simple interest in given principle ,time,rate.

DECLARE FUNCTION si(p,t,r)
cls
input "enter principle,time,rate=";p,t,r
print "simple interest=";si(p,t,r)
end

function si(p,t,r)
si=(p*t*r)/100
end function

4. Wap to create a function area(l,b,h) to calculate and print total surface area(tsa) of box

DECLARE FUNCTION area(l,b,h)
cls
INPUT “ENTER LENGTH,BREADTH,HEIGHT";l,b,h
print "total surface area of box is ";area(l,b,h)
end

function area(l,b,h)
area=2*(l*b+b*h+h*l)
end function

5. Wap to convert octal number to equivalent decimal number


DECLARE FUNCTION d(b)
cls
input "enter  number in octal=";b
print "octal to decimal =";d(b)
end

function d(b)
while b<>0
r=b mod 10
oc=r*8^p
p=p+1
b=b\10
wend
D=oc
end function

6.wap to print smallest number among three numbers

declare function s(a,b,c)
cls
input "enter  three numbers=";a, b, c
print "smallest number is =";s(a,b,c)
end

function s(a,b,c)
if a<b and a<c then
 s=a
elseif b<a and b<c then
s=b
else
s=c
end function

7. Wap to declare user defined to  count total numbers of vowels in given string

declare function s(p$)
cls
input "enter string =";p$
print "total number of vowels=";s(p$)
end

function s(p$)
p$=lcase$(p$)
for i= 1 to len(p$)
b$=mid$(p$,i,1)
if b$="a" or  b$="e" or  b$="i" or  b$="o" or  b$="u" then b=b+1
next i
s=b
end function

8. Wap to declare user defined to  count total numbers of space  in given string

declare function s(p$)
cls
input "enter string =";p$
print "total number of space =";s(p$)
end

function s(p$)
for i= 1 to len(p$)
b$=mid$(p$,i,1)
if b$=" " then b=b+1
next i
s=b
end function

9. Wap to calculate area of circle.

declare function s(r)
cls
input "enter radius =";r
print "total area of circle =";s(r)
end
function s(r)
s=22/7*r^2
end function

10. Wap to declare user  function rev(n) that returns a number in  reversed order (e.g 123 to 321)

declare function rev(n)
cls
input "enter  number =";n
print "reverse order =";rev(n)
end

function rev(n)
while n<>0
r=n mod 10
a=(r*10)+a
n=n\10
wend
n=a
end function

11. WAP TO  ASKS THREE NUMBERS AND DISPLAYS THE MIDDLE NUMBER AMONG THEM.

DECLARE FUNCTION A(B,C,D)
CLS
INPUT B,C,D
PRINT "middle no.  is";A(B,C,D)
END
FUNCTION A(B,C,D)
IF (B>C AND B<D) OR (B<C AND B>D) THEN
A=B
ELSEIF (C>D AND C<D) OR (C<D AND C>D) THEN
A=C
ELSE
A=D
END IF
END FUNCTION

12.WAP TO CHECK WHETHER THE SUPPLIED WORD IS PALINDROME OR NOT
.

DECLARE FUNCTION B$(A$)
CLS
INPUT"ENTER THE WORD";A$
PRINT"WORD IS";B$(A$)
END
FUNCTION B$(A$)
FOR I=LEN(A$) TO 1 STEP -1
R$=R$ +MID$(A$,I,1)
NEXT I
IF R$=A$ THEN
B$="IS PALINDROME"
ELSE
B$="IS NOT PALINDROME"
END IF
END FUNCTION

13.WAP TO CALCULATE AND PRINT AREA(A) OF A SQUARE.


DECLARE FUNCTION AREA (L)
CLS
INPUT "enter lenght of square";L
PRINT"area of square is";AREA(L)
END
FUNCTION AREA(L)
AREA=L^2
END FUNCTION

14.WAP TO CONVERT TEMPERATURE CENTIGRADE IN FAHRENHEIT.(HINT:F=(9/5)C+32)


DECLARE FUNCTION F(C)
CLS
INPUT"ENTER TEMPERATURE IN CENTIGRADE";C
PRINT"FAHRENHEIT IS";F(C)
END
FUNCTION F(C)
F=(9/5)*C+32
END FUNCTION

15.WAP TO DETECT AND PRINT WHETHER AN ENTERED NUMBER IS ODD OR EVEN
.

DECLARE FUNCTION A$(N)
CLS
INPUT"ENTER NUMBER";N
PRINT"NUMBER IS";A$(N)
END
FUNCTION A$(N)
IF N MOD 2=0 THEN
A$="IS EVEN"
ELSE
A$="IS ODD"
END IF
END FUNCTION


16.WAP TO CHECK WHETHER THE ENTERED NUMBER IS PRIME OR COMPOSITE.

DECLARE FUNCTION A$(N)
CLS
INPUT"ENTER NUMBER";N
PRINT n; "NUMER IS";A$(N)
END
FUNCTION A$(N)
FOR I=1 TO N
IF N MOD I =0 THEN F=F+1
NEXT I
IF F=2 THEN
A$= " PRIME"
ELSE
A$="COMPOSITE"
END IF
END FUNCTION

17.WAP TO FIND LONGEST STRINGS AMONG THREE NUMBERS.


DECLARE FUNCTION A$(B$,C$,D$)
CLS
INPUT"ENTER THREE STRINGES";B$,C$,D$
PRINT"LONGEST hSTRINGES=";A$(B$,C$,D$)
END
FUNCTION A$(B$,C$,D$)
B=LEN(B$)
C=LEN(C$)
D=LEN(D$)
IF (B>C AND B>D) THEN
A$=b$
ELSEIF (C>B AND C>D) THEN
A$=C$
ELSE
A$=D$
END IF
END FUNCTION

18.WAP TO CHECK WHETHER ENTERED NUMBER IS PERFECT SQUARE OR NOT.


DECLARE FUNCTION A$(N)
INPUT"ENTER NUMBER ";N
PRINT"NUMBER IS";A$(N)
END
FUNCTION A$(N)
S= N^(1/2)
IF S=INT(S) THEN
A$= " IS PERFECT SQUARE"
ELSE
A$= " IS NOT PERFECT SQUARE"
END IF
END FUNCTION

19. Wap to creat a function square(n) and to find square number then use this function to calculate sum of square of numbers from 1 to that number.

Declare function a(n)
Cls
Input "enter any number";n
Print "sqaure of ";n^2
Print "sum of square=";a(n)
End
Function a(n)
For i=1 to n
Sum=i^2+sum
Next i
A=sum
End function


20.WAP TO CREATE A FUNCTION PROCEDUERE CHECK$(A,B,C) TO ENTER LENGTH OF THREE SIDES THEN CHECK WHETHER TRIANGLE CAN BE FORM OR NOT. 

DECLARE FUNCTION CHECK$(A,B,C)
CLS
INPUT "ENTER LENGTH OF THREE SIDES";A,B,C
PRINT "TRIANGLE ";CHECK$(A,B,C)
END
FUNCTION CHECK$(A,B,C)
IF (A+B)>C  OR (A+C)>B OR (B+C)> A THEN
CHECK$=" CAN BE FORMED"
ELSE
CHECK$="CANNOT BE FORMED"
END IF
END FUNCTION


21. Wap to creat a function square(n) and to find square number then use tis function to calculate sum of square of numbers from 1 to that number.

Declare function a(n)
Cls
Input "enter any number";n
Print "sqaure of ";n^2
Print "sum of square=";a(n)
End
Function a(n)
For i=1 to n
Sum=i^2+sum
Next i
A=sum
End function

22.wap to count the occurance (repetation) of entered character in a given string:

declare function r(a$,e$)
Cls
Input "enter any string";a$
Input "enter any character; "e$
Print "repetation of ";e$;"in";a$;"is"; r(a$,e$)
End
Function r(a$,e$)
For i =1 to len(a$)
If mid$(a$,i, 1)=e$ then f=f+1
Next i
r=f
End function

23. Wap to calculate total distance(s) covered by an object where initial velocity (u),  acceleration(a), and time(t) is input from the keyboard by user while executing the program. (hint=ut+1/2.at^2)

declare function s(a,u,t)
cls
Input "enter accelaration, initial velocity, time";a, u, t
Print "total distance=";s(a,u,t)
End
Function s(a,u,t)
s=u*t+1/2*a*t^2
End function

24.wap to calculate to input complete date of birth of a person then determine his/her present age.

Declare function a(p$)
Cls
Input "enter your date of birth in dd-mm-yy";p$
Print "your present age is";a(p$)
End
Function a(p$)
b$=date$
c$=right$(b$,4)
p$=right$(p$,4)
a=len(p$)-len(c$)
End function

25.wap to define a function procedure area(R) to calculate and display area of sphere.

declare function area(r)
Cls
Input "enter a radius of sphere";r
Print "area of sphere=";area(r)
End
function area(r)
area=(4/3)*(22/7)*r^3
End function

26.wap to create three different functions for calculating and printing sum, difference and product of two entered number.

Declare function sum(a,b)
declare function diff(a,b)
declare function product(a,b)
cls
input "enter any two no. ";a, b
Print "sum=";sum(a,b)
Print "difference =";diff(a,b)
Print "product=";product(a,b)
End
Function  sum(a, b)
sum=a+b
End function
Function  diff(a, b)
if a<b then swap a, b
diff=a-b
End function
Function  product(a, b)
product =a*b
End function


 27.Wap a program to calculate area of traiangle where values of three sides are given.
Declare function area(a,b,c,)
Cls
Input "enter the length of traiangle=";a, b, c
Print "area of triangle is ";area(a,b,c)
End
Function area(a,b,c)
S=(a+b+c)/2
Area=(s*(s-a) *(s-b) *(s-c)) ^1/2
End function

28. Wap to check Weather a enterd no. is exactly divisible by 13 or not.
Declare function div$(n)
  cls
  Input "enter any no. ";n
  Print n; div$(n);"divisible by 13"
  End
  Function div$(n)
  If n mod 13=0 then
        Div$="is"
    Else
        Div$="is not"
  End if
end function

29. Wap to define an user's function Reverse(N) to display an entered no.  in reverse order. 
Declare function reverse(n)
Cls
Input "enter a no. ";n
Print "reverse order of ";n; "is";reverse(n)
End
Function reverse(n)
While n<>0
R=n mod 10
Rev=(Rev*10)+R
N=N/10
Wend
Reverse=rev
End function

30.Wap to calculate LCM of two eneterd no.
Declare function lcm(a,b)
Cls
Input "enter any two no. ";a, b
Print "lcm=";lcm(a,b)
End
Function lcm(a,b)
if a>b Then Swap a, b
For i=1 to a
If a mod i=0 and b mod i=0 then hcf=i
Next i
Lcm=(a*b)/hcf
End function



31.wap to create a function rev$(w$,r$)to display the entered  string in reverse order

declare function rev$(w$,r$)
cls
input "enter  two string =";w$,r$
print " REVERSE ORDER IS=";rev$(w$,r$)
end

function rev$(w$,r$)
w$=lcase$(w$)
for i= len(w$) TO 1 STEP -1
b$=b$+mid$(w$,i,1)
next i
r$=lcase$(r$)
for i=len(r$) TO 1 STEP -1
c$=c$+mid$(r$,i,1)
next i
rev$=b$+"AND"+c$
end function

32.wap to convert temperature  farenheight to centigrade.

declare function s(r)
cls
input "enter  temperature in farenheight =";r
print " temperature in centigrade=";s(r)
end

function s(r)
s=(5/9)*(r-32)
end function

33.wap to check wheather a number is palindrome or not.

declare function v$(n)
cls
input "enter  number =";n
print "enter number  is";v$(n)
end

function v$(n)
b=n
while n<>0
r=n mod 10
o=(r*10)+o
n=n\10
wend
if  o= b then
v$="palindrome"
else
v$=" not palindrome"
end function

34.wap to create  function product(N) to calculate and print the product of each digit of user enter number.

declare function product(N)
cls
input "enter  number =";N
for i=1 to 10
c=N*i
print product(N)
next i
end
function product(N)
product=c
end function

No comments:

Post a Comment

MCQ Question Bank Microsoft PowerPoint