0% found this document useful (0 votes)
17 views5 pages

QB Sample

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

QB Sample

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Sample QBASIC Programs.

1. Write a program to find the given number is positive, negative or zero.


Cls
input “Enter any number”; num
if num > 0 then
print “The number is positive”
else if num < 0 then
print “The number is negative”
else
print “The number is zero”
end if
2. Program to print Fibonacci Series: 1 1 2 3 5 8 ….10th term.
Cls
a=1
b=1
print a; b;
for I = 1 to 10
c = a+b
print c;
a=b
b=c
next I
end
3. Write a program to display all the natural numbers up to 500.
cls
for i = 1 to 500
print i
next i
end
4. Write a program to display the series 2 3 5 8 12 17………. upto 10th terms.
cls
n=2
for I = 1 TO 10
PRINT n;
n=n+i
next i
end
5. Write Program to display 1 5 9 13 up to nth term
cls
input “Enter any number”;n
for i = 0 TO n
print 4 * i + 1;
next i
end
6. Write a program to count no. of odd digits and even digits from the user’s
input of 5 numbers.
cls
input “enter any 5 numbers”: n
while n > 0
r = n mod 10
if r mod 2 = 0 then
e = e+1
else
o = o+1
end if
n = n / 10
wend
print “Number of even digits”; e
print “Number of odd digits”; o
end

7. Write a program to calculate the product of each digit of user entered the
digit.
cls
input “ Enter any number”;n
p =1
while n <> 0
r = n mod 10
p = p*r
n = n / 10
wend
print
print “Product of each digits”;p
end

8. Write a program to display the following patterns:


1
12 cls
for i = 1 TO 5
123
for j = 1 TO i
1234 print j;
12345 next j
print
next i
end
12345 cls
for i = 5 to 1 step -1
1234
for j = 1 TO i
123 print j;
12 next j
print
1 next i
end

1 cls
22 for i = 1 to 5
333 for j = 1 to i
4444 print i;
55555 next j
print
next i
end

55555 cls
4444 for i = 5 to 1 step -1
333 for j = 1 to i
22 print i;
1 next j
print
next i
end

54321 cls
5432 for i = 1 to 5
543 for j = 5 to i step -1
54 print j;
5 next j
print
next i
end
54321 cls
4321 for i = 5 to 1 step -1
321 for j = i to 1 step -1
21 print j;
1 next j
print
next i
end

9. Write a program to check whether the given number is perfect square or


not(using function).
cls
input “Enter any number”;n
s = sqr(n)
if s = int(s) then
print “The Number is perfect square number”;
else
print “The Number is not perfect square number”;
end if
end
10.Write a program to input any string and reverse it.
cls
input “Enter a string”;str$
for i = len(str$) to 1 step -1
s$ = mid$(str$, i, 1)
x$ = x$ + s$
next i
print “Reversed string is”; x$
end
11.Write a program to input a long string and display only initial character of
each word.
cls
input “Enter a string”;str$
c$ = left$(str$,1)
for i = 1 to len(str$)
s$ = mid$(str$, i, 1)
if s$ = “ ” then c$ = c$ + mid$(str$, i+1, 1)
next i
print c$
end
12.Write a program to check whether a character is capital or small letter.
Cls
Input “Enter a character”:c$
if c$ = ucase$(c$) then
print “Capital letter”
else
print “Small letter”
end if
end
13. Write a program to count number of words in the given string
cls
let c = 1
input “Enter a sentence”; s$
for I = 1 to len(s$)
t$ = mid$(s$,i,1)
if t$ = “ ” then c = c+1
next I
print “No. of words is”; c
end

You might also like