Social Icons

Pages

Wednesday, May 2, 2012

QBasic Programming


Write a Program to calculate the:

1.    Area of rectangle.
Rem
Cls
Input "Enter Length "; l
Input "Enter Breadth"; b
a = l * b
Print "Area of Rectangle ="; a
End

2. Perimeter of Rectangle. Rem
Cls
 Input "Enter the Length"; l
Input "Enter the Breadth"; b
p = 2 * (l * b)
Print "perimeter of Rectangle ="; p
End

3. Area and Perimeter of Square.
Rem
Cls
Input "enter the length"; l
a = l ^ 2
Print "area of square"; a
End

Rem
Cls
Input "enter the length "; l
p=4 * l
Print "perimeter of square ="; p
End

4.     Area of Circle.
Rem
Cls
CONST Pie = 3.14
Input "enter the radius "; r
a = pie * r *2
Print "the area of circle ="; a
End


5. Circumference of circle.
Rem
Cls
CONST pie = 3.14
Input "enter the radius"; r
c = 2 * pie * r
Print "the circumference of circle ="; c
End

6.    Interest ( I = PTR/100)
Rem
Cls
Input "enter the Principle"; p
Input "enter the time"; t
Input "enter the rate"; r
i = (p * t * r) / 100
Print "interest="; i
End

7.    Volume of a cubical box.( V = l * b * h)
Rem
Cls
Input "enter the length"; l
Input "enter the breadth"; b
Input "enter the height"; h
v = l * b * h
Print "Volume of cube ="; v
End

8.    Sum, product, average and difference of two numbers.
Rem
Cls
Input "enter the first number"; a
Input "enter the second number"; b
s = a + b
p = a * b
avg = s / 2
d = a - b
Print " The sum ="; s
Print "the product ="; p
Print "the average ="; avg
Print "the difference ="; d
End

9.    Square of a given number.
 Rem
Cls
Input "enter the number "; n
s = n * n
Print "the square of number is"; s
End

10. Cube of given number.
Rem
Cls
Input "enter the number"; n
c = n * n * n
Print "cube of given number is"; c
End

11.Convert temperature given in centigrade into Fahrenheit.
             [(F = 9 * c)/5 +32]
Rem
Cls
Input "enter temperature in Centigrade"; c
f = (9 * c)/5 + 32
Print "Converted Fahrenheit ="; f
End

12.Find the greatest among two numbers.
Rem
Cls
Input "enter first number"; n1
Input "enter second number"; n2
If n1 > n2 then
Print n1;"is greatest"
Else
Print n2;"is greatest"
End if
End

13. Find the smallest among two numbers.
Rem
Cls
Input "enter first number"; n1
Input "enter second number"; n2
If n1 < n2 then
Print n1;"is smallest"
Else
Print n2;"is smallest"
End if
End

14. Find the greatest among three numbers.
Rem
Cls
Input "enter first number"; n1
Input "enter second number"; n2
Input "enter third number"; n3
If n1 > n2 then and n1 > n3
Print n1;"is greatest"
Elseif n2 > n1 and n2 > n3
Print n2;"is greatest"
Else
Print n3;"is greatest"
End if
End

15. Find the smallest among three numbers.
Rem
Cls
Input "enter first number"; n1
Input "enter second number"; n2
Input "enter third number"; n3
If n1 < n2 then and n1 < n3
Print n1;"is smallest"
Elseif n2 < n1 and n2 < n3
Print n2;"is smallest"
Else
Print n3;"is smallest"
End if
End

16.   Input ten different numbers and find the greatest.
Rem
Cls
c =1
Input "enter first number"; g
Do
Input "enter next number"; n
If n > g then
g = n
Endif
c = c + 1
If c = 10 the Exit Do
Print g;" is greatest number"
End

17. Input ten different numbers and find the smallest.
Rem
Cls
c =1
Input "enter first number"; g
Do
Input "enter next number"; n
If n < g then
g = n
Endif
c = c + 1
If c = 10 the Exit Do
Print g;" is smallest number"
End

18.Reverse the digits/number.
Rem
Cls
s = 0
Input "enter any number"; n
Do While n < > 0
r = n mod 10
s= s * 10 + r
n = n \ 10
Loop
Print "Reverse number ="; s
End

19. Find the sum of Digits.
Rem
Cls
s = 0
Input "enter digits"; n
Do While n < > 0
r = n mod 10
s = s + r
n = n \ 10
Loop
Print "The sum of digits ="; s
End

20. Find whether the given number is palindrome or not.
Rem
Cls
s = 0
Input "enter any number"; n
a = n
Do While n < > 0
r = n mod 10
s = s * 10 + r
n = n \ 10
Loop
    If a = s then
Print a; "is palindrome"
Else
Print a; "is not palindrome"
Endif
End

21. Find the sum of square of numbers.
Rem
Cls
s = 0
Input "enter the number"; n
While n < > 0
r = n mod 10
s = s + r ^ 2
n = n \ 10
Wend
Print "sum of square ="; s
End

22. Find the sum of cube of numbers.
Rem
Cls
s = 0
Input "enter the number"; n
While n < > 0
r = n mod 10
s = s + r ^ 3
n = n \ 10
Wend
Print "sum of square ="; s
End

23. Display the sum of square of numbers from 1 to 10.
Rem
Cls
s = 0
For i = 1 to 10
s = s + i ^2
Next i
Print "The sum of square of numbers from 1 to 10 ="; s
End

24. Display the sum of cube of numbers from 1 to 10.
Rem
Cls
s = 0
For i = 1 to 10
s = s + i ^3
Next i
Print "The sum of square of numbers from 1 to 10 ="; s
End

25. Find whether the given number is Armstrong or not.
Rem
Cls
s = 0
Input "enter any number "; n
a = n
While n < > 0
r = n mod 10
s = s + r ^ 3
n = n \ 10
Wend
If a = s then
Print a;" is Armstrong number"
Else
Print a;" is not Armstrong number"
End if
End

26. Display all Armstrong numbers from 1 to 1000.
Cls
For i = 1 to 1000
s = 0
a = i
While a < > 0
r = a mod 10
s = s + r ^3
a = a \ 10
Wend
If i = s then print i
Next i
End

27. Find whether the given number is prime or composite.
Rem
Cls
Input "enter any number "; n
Flag = 0
For i = 2 to n / 2
r = n mod i
If r = 0 then
Flag = 1
Exit for
End if
Next i
If flag = 1 then
Print n;" is composite number"
Else
Print n;" is prime number"
End if
End

28. Display all prime numbers from 1 to 100.
Rem
Cls
For i = 1 to 100
Flag = 0
For j = 2 to i / 2
r = i mod j
If r = 0 then
Flag = 1
Exit for
End if
Next j
If flag = 0 then
Print i
End if
Next i
End

29. Find the factorial of a given number.
Cls
Rem
Input "enter any number"; n
f = 1
For i = 1 to n
f = f * i
Next i
Print "factorial of number ="; f
 End

30. Display the multiplication table of a given number.
Cls
Input "enter any number"; n
For i = 1 to 10
c = n * i
Print n; "x";"="; c
Next i
End

31. All natural number from 1 to 100.
Rem
Cls
For a = 1 to 100
Print a
Next a
End

32. Even numbers from 1 to 100.
Rem
Cls
For a = 2 to 100 step 2
Print a
Next a
End

33. Odd numbers from 1 to 100.
Rem
Cls
For a = 1 to 100 step 2
Print a
Next a
End

34. All natural numbers from 1 to 100 in descending order.
Rem
Cls
For a = 100 to 1 step -1
Print a
Next a
End

35. Even numbers from 1 to 100 in descending order.
Rem
For a = 100 to 1 step - 2
Print a
Next a
End

36. Odd numbers from 1 to 100 in descending order.
Rem
Cls
For a = 99 to 1 step - 2
Print a
Next a
End

37. Sum of all natural numbers from 1 to 100.
Rem
Cls
s = 0
For a = 1 to 100
s = s + a
Next a
Print "the sum of numbers ="; s
End

38. Sum of all even numbers from 1 to 100.
Rem
Cls
s = 0
For a = 2 to 100 step 2
s = s + a
Print "the sum of even numbers from 1 to 100 ="; s
Next a
End

39. Sum of all odd numbers from 1 to 100.
Rem
Cls
s = 0
For a = 1 to 100 step 2
s = s + a
Next a
Print "the sum of odd numbers from 1 to 100 ="; s
End

40. Print all natural numbers up to given number and also print its sum.
Rem
Cls
s = 0
Input "enter the range "; n
a = 1
While a < = n
s = s + a
a = a + 1
Wend
Print "All natural numbers are:"; a
Print "The sum of natural numbers ="; s
End

 42. Print even numbers up to given number and also print its sum
Rem
Cls
s = 0
Input "enter the range "; n
a = 2
While a < = n
s = s + a
a = a + 2
Wend
Print "even numbers are"; a
Print "The sum of even numbers ="; s
End

43. Print odd numbers up to given number and also print its sum.
Rem
Cls
s = 0
Input "enter the range "; n
a = 1
While a < = n
s = s + a
a = a + 2
Wend
Print "odd numbers are"; a
Print "The sum of odd numbers ="; s
End

44. Input ten different numbers and find the sum.
Cls
s = 0
For i = 1 to 10
Input "enter any ten numbers"; n
s = s + n
Next i
Print "sum ="; s
End

45. Input ten different numbers and find the sum of even numbers.
Cls
s = 0
For i = 1 to 10
Input "enter any ten numbers"; n
If n mod 2 = 0 then
s = s + n
End if
Next i
Print "The sum of even numbers ="; s
End

46. Input ten different numbers and find the sum of odd numbers.
Cls
s = 0
For i = 1 to 10
Input "enter any ten numbers"; n
If n mod 2 < > 0 then
s = s + n
End if
Next i
Print "The sum of odd numbers ="; s
End

Generate the series up to 10th term

47. 5, 25, 125......................
Rem
Cls
a = 5
For i = 1 to 10
Print a
a = a * 5
Next i
End


48. 100, 98.5, 97, 95.5....................
Rem
Cls
a = 100
For i = 1 to 10
Print a
a = a - 1.5
Next i
End

49. 0.3, 0.33, 0.333, 0.3333.......................
Rem
Cls
a = 0.3
For i = 1 to 10
Print a
a = a / 10 + 0.3
Next i
End

51. 1, 4, 9, 16...............................
Rem
Cls
For i = 1 to 10
a = i ^ 2
Print a
Next I
End

52. 1, 8, 27, 64..........................................
Rem
Cls
For i = 1 to 10
a = i ^ 3
Print a
Next i
End

53. 1, 11, 111, 1111............................ 5th term.
Rem
Cls
a = 1
For b = 1 to 5
Print a
a = a * 10 + 1
Next b
End
54. 55555, 5555, 555, 55, 5
Rem
Cls
a = 55555
For i = 1 to 5
Print a
a = (a - 5) / 10
Next i
End

55. Write to program to find the sum and the average of given data.
Data 5, 15, 20, 80, 90, 100, 70, 200, 20, 10
Rem
Cls
Dim a (10)
s = 0
For i = 1 to 10
Read a (i)
s = s + a (i)
Next i
avg = s / 10
Print "The sum of given ten numbers ="; s
Print "The Average of given the numbers ="; avg
Data 5 15 20 80 90 100 70 200 20 10
End

57. Find whether the given string is palindrome or not.
Rem
Cls
s = 0
Input "enter any number"; n
a = n
Do while n < > 0
r = n mod 10
s = s * 10 + r
n = n \ 10
Loop
If a = s then
Print a; "is palindrome number"
Else
Print a; "is not palindrome number"
End if
End

58. Count the total number of letters in a given string.
Rem
Cls
Input "enter the string "; a$
Print Len (a$)
End

1 comment: