0% found this document useful (0 votes)
7 views16 pages

Basic Programs for Triangle and Numbers

top basis programming for tripura university

Uploaded by

name1522000
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)
7 views16 pages

Basic Programs for Triangle and Numbers

top basis programming for tripura university

Uploaded by

name1522000
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

Q.1.

Write a program in Basic to find largest of three sides of a


triangle. First check whether triangle formation is possible or not.

10 Rem "Let us verify the triangle formation is possible or not"


20 Input "give three sides of a triangle"; a, b, c
30 If (a + b) > c And (b + c) > a And (a + c) > b Then 40 Else GoTo 60
40 Print "formation of triangle is possible"
50 GoTo 80
60 Print "formation of triangle is not possible"
70 GoTo 140
80 If (a > b And a > c) Then 90 Else GoTo 100
90 Print "the largest side is"; a
100 If (b > a And b > c) Then 110 Else GoTo 120
110 Print "the largest side is"; b
120 If (c > a And c > b) Then 130 Else GoTo 140
130 Print "the largest side is"; c
140 End

-------------------------------------------------------
[Link] a program in Basic to area of a triangle using Hero’s
formula. First check whether triangle formation is possible or not.

10 Rem "Calculate the area of triangle using hero's formula"


20 Input "give three sides of a triangle"; a, b, c
30 If (a + b) > c And (b + c) > a And (a + c) > b Then 40 Else GoTo 60
40 Print "formation of triangle is possible"
50 GoTo 80
60 Print "formation of triangle is not possible"
70 GoTo 110
80 s = (a + b + c) / 2
90 h = (s * (s - a) * (s - b) * (s - c)) ^ (1 / 2)
100 Print "the area of the triangle"; h
110 End
----------------------------
[Link] a program in Basic to check right angle triangle
formation is possible or not. First check triangle formation
possible or not.

10 Rem "Let us verify the triangle formation is possible or not"


20 Input "give three sides of a triangle"; a, b, c
30 If (a + b) > c And (b + c) > a And (a + c) > b Then 40 Else GoTo 60
40 Print "formation of triangle is possible"
50 GoTo 80
60 Print "formation of triangle is not possible"
70 GoTo 120
80 If (a ^ 2 + b ^ 2) = c ^ 2 Or (b ^ 2 + c ^ 2) = a ^ 2 Or (c ^ 2 + a
^ 2) = b ^ 2 Then 90 Else GoTo 110
90 Print "the triangle is a right-angled triangle"
100 GoTo 120
110 Print "the triangle is not right-angled triangle"
120 End

--------------------------------------------------

[Link] a program in Basic to input an integer and print all its


divisor at the output.

10 Rem "Input an integer and print all its divisors at its output"
20 Input "give the integer "; a
30 For i = 1 To a
40 d = a Mod i
50 If d = 0 Then 60 Else GoTo 70
60 Print i; "is the divisor of"; a
70 Next i
80 End
-------------------------------------------
[Link] a program in Basic to input 10 random number and print
all odd number at the output.

10 Rem "Input 10 numbers and print all odd numbers at the output"
20 Print " give the numbers below"
30 Dim a(10)
40 For i = 1 To 10
50 Input a(i)
60 Next i
70 Print "the odd numbers are"
80 For i = 1 To 10
90 c = a(i) Mod 2
100 If c <> 0 Then Print a(i)
110 Next i
120 End
--------------------------------------------------

[Link] a program in Basic to input 10 random number and print


all even number at the output.

10 Rem "input 10 numbers and print all even numbers at the output"
20 Print " give the numbers below"
30 Dim a(10)
40 For i = 1 To 10
50 Input a(i)
60 Next i
70 Print "the even numbers are"
80 For i = 1 To 10
90 c = a(i) Mod 2
100 If c = 0 Then Print a(i)
110 Next i
120 End
-----------------------------------------------
[Link] a program in Basic to find all prime number from 1 to
100.

10 Rem "find all the prime numbers from 1 to 100"


20 For n = 1 To 100
30 c = 0
40 For i = 1 To n
50 If n Mod i = 0 Then c = c + 1
60 Next i
70 If c = 2 Then Print n
80 Next n
90 End
---------------------------------------------------

[Link] a program in Basic to find sum of 10 natural numbers.

10 Rem "find the sum of 10 natural numbers"


20 Dim a(10)
30 s = 0
40 Print "the natural numbers are given as"
50 For i = 1 To 10
60 Input a(i)
70 s = s + a(i)
80 Next i
90 Print " the sum of 10 natural numbers"; s
100 End
--------------------------------------
[Link] a program in Basic to find factorial of a number N.

10 Rem "find the factorial of a given number N"


20 Input "give the number N"; N
30 f = 1
40 For i = N To 1 Step -1
50 f = f * i
60 Next i
70 Print "the factorial of a number N is= "; f
80 End
------------------------------------------------

[Link] a program in Basic to find LCM of two number as input.

10 Rem "find LCM of two numbers"


20 Input "Enter the first number"; a
30 Input "enter the second number"; b
40 m = a
50 n = b
60 While a <> 0
70 r = b Mod a
80 b = a
90 a = r
100 Wend
110 l = (m * n) / b
120 Print "LCM is"; l
130 End

--------------------------------------------
[Link] a program in Basic to find HCF of two number as input.
10 Rem "find HCF of two numbers"
20 Input "Enter the first number"; a
30 Input "enter the second number"; b
40 m = a
50 n = b
60 While a <> 0
70 r = b Mod a
80 b = a
90 a = r
100 Wend
110 l = (m * n) / b
120 Print "HCF is"; b
130 End
-------------------------------------------------------
[Link] a program in Basic to input 10 number and arrange them
in ascending order.
10 Rem "arrange the numbers in ascending order"
20 Dim n(10)
30 Print "enter the numbers below"
40 For i = 1 To 10
50 Input n(i)
60 Next i
70 For i = 1 To 10
80 For j = 1 To 10 - i
90 If n(j) > n(j + 1) Then Swap n(j), n(j + 1)
100 Next j
110 Next i
120 Print "the numbers are arranged in ascending order"
130 For i = 1 To 10
140 Print n(i)
150 Next i
160 End
-------------------------
[Link] a program in Basic to input 10 number and arrange them
in descending order.
10 Rem "arrange the numbers in descending order"
20 Dim n(10)
30 Print "enter the numbers below"
40 For i = 1 To 10
50 Input n(i)
60 Next i
70 For i = 1 To 10
80 For j = 1 To 10 - i
90 If n(j) < n(j + 1) Then Swap n(j), n(j + 1)
100 Next j
110 Next i
120 Print "the numbers are arranged in descending order"
130 For i = 1 To 10
140 Print n(i)
150 Next i
160 End
---------------------------------
[Link] a program in Basic to input a 10 number and arrange
them in reverse order. Print both original and reverse order
Answer Option-1
10 Rem" print the given numbers in reverse order"
20 Print "give the numbers"
30 For i = 1 To 10
40 Input n(i)
50 Next i
60 Print "the numbers in reverse order is"
70 For i = 10 To 1 Step -1
80 Print n(i)
90 Next i
100 End
---------------------------------------------------

[Link] a program in Basic to input a 10 number and arrange


them in reverse order. Print both original and reverse order
Answer Option-2
10 Rem " 10 number print in reverse order"
20 Cls
30 Dim A(100)
40 Dim B(100)
50 Print "Enter the 10 nos"
60 For I = 1 To 10
70 Input A(I)
80 B(11 - I) = A(I)
90 Next I
95 Print "original order", "reverse order"
100 For I = 1 To 10
110 Print A(I), Tab(30); B(I)
120 Next I
130 End
----------------------------------------
[Link] a program in Basic to print 10 Fibonecci number where
T(1)=0, T(2)=1.
Answer Option-1
10 Rem "Fiboneci series 10 terms"
20 CLS
30 Dim T(50)
40 T(1) = 0
50 T(2) = 1
60 For I = 3 To 10
70 T(I) = T(I - 1) + T(I - 2)
80 Next I
90 Print "Fibonecci series first 10 terms are"
100 For I = 1 To 10
110 Print T(I);
120 Next I
130 End
-----------------------------------------

[Link] a program in Basic to print 10 Fibonecci number where


T(1)=0, T(2)=1.
Answer Option-2
10 Rem "print 10 fibonacci numbers at the output"
15 Dim t(20)
20 t(1) = 0
30 t(2) = 1
31 Print t(1)
32 Print t(2)
40 For i = 3 To 10
50 t(i) = t(i - 1) + t(i - 2)
60 Print t(i)
70 Next i
80 End
--------------------------------
[Link] a program in Basic to convert Celsius to Fahrenheit
Scale
Answer Option-1

10 Rem "input a temperature in Celsius and convert it into Fahrenheit


scale"
20 Print "temperature in Celsius scale"
30 Input c
40 f = (9 * c / 5) + 32
50 Print "temperature in Fahrenheit scale"; f
60 End
-------------------
[Link] a program in Basic to convert Celsius to Fahrenheit
Scale
Answer Option-2

10 Rem " Celsius to Fahrenheit"


20 Cls
30 Print "Temperature in Celsius scale"
40 Input C
50 F = ((C / 5) * 9) + 32
60 Print "Temperature in Fahrenheit is "; F
70 End
-------------------
[Link] a program in Basic to convert Fahrenheit to Celsius
Scale
Answer Option-1
10 Rem "Fahrenheit to Celsius"
20 Cls
30 Print "Temperature in Fahrenheit scale"
40 Input F
50 C = (F - 32) * (5 / 9)
60 Print "Temperature in Celsius is "; C
70 end
---------------------------------

[Link] a program in Basic to convert Fahrenheit to Celsius


Scale
Answer Option-2
10 Rem "input a temperature in Fahrenheit and convert it into Celsius
scale"
20 Print "temperature in Fahrenheit scale"
30 Input f
40 c = (f - 32) * 5 / 9
50 Print "temperature in celsius scale"; c
60 End
------------------
[Link] a program in Basic to find surface area and volume of a
sphere
Answer Option-1

10 Rem "find the area and volume of a sphere"


20 Print "the radius of a sphere in cm"
30 Input r
40 a = 4 * 3.14 * r * r
50 Print "area of sphere a="; a
60 v = 4 * 3.14 * r * r * r / 3
70 Print "volume of the sphere v="; v
80 End
-----------------------------------

[Link] a program in Basic to find surface area and volume of a


sphere
Answer Option-2
10 Rem "Calculate area and volume of a sphere"
20 Cls
30 Print "Enter the radius of sphere in cm"
40 Input R
50 S = 4 * 3.14 * R * R
60 V = (4 / 3) * 3.14 * R * R * R
70 Print "Surface area="; S, "Volume="; V
80 End
----------------------------
[Link] a program in Basic to input five digit number and
reverse the digit and print both five digit number at output.
Answer Option-1
10 Rem "arrange the digits of a 5 digit number in reverse order"
20 Input "enter a 5 digit number"; n
30 s = 0
40 While n <> 0
50 r = n Mod 10
60 s = s * 10 + r
70 n = n \ 10
80 Wend
90 Print "reverse digits"; s
100 End
------------------------

[Link] a program in Basic to input five digit number and


reverse the digit and print both five digit number at output.
Answer Option-2
10 Rem "Five digit number reverse"
20 Cls
30 Print "Enter the 5 digits number"
40 Input A
50 B1 = Int(A / 10000)
60 B = A - (B1 * 10000)
70 B2 = Int(B / 1000)
80 C = B - (B2 * 1000)
90 B3 = Int(C / 100)
100 D = C - (B3 * 100)
110 B4 = Int(D / 10)
120 B5 = D - (B4 * 10)
130 AR = B5 * 10000 + B4 * 1000 + B3 * 100 + B2 * 10 + B1
140 Print "original no"; A, "reverse no"; AR
150 End
[Link] a program in Basic to input focal length and object
distance and find the image distance of convex lens.
Answer Option-1
10 Rem "calculate the image distance when object distance is given"
20 Print "give the focal length of convex lens in cm"
30 Input f
40 Print "give the object distance in cm "
50 Input u
60 v = f * u / (u + f)
70 Print "image distance in cm "; v
80 End
-------------------------------------

[Link] a program in Basic to input focal length and object


distance and find the image distance of convex lens.
Answer Option-2
10 Rem "image distance of a convex lens"
20 Cls
30 Print "Enter the Focal length of lens"
40 Input F
50 Print "Enter the object distance of lens"
60 Input U
70 V = 1 / ((1 / F) - (1 / U))
80 Print "Image distance is"; V
90 end

---------------------------
[Link] a program in Basic to input five resistance and find
equivalent resistance of parallel combination.
Answer Option-1
10 Rem "find the equivalent resistance of five resistances in parallal
combination"
20 Print "give five resistance"
30 Input a, b, c, d, e
40 p = (1 / a) + (1 / b) + (1 / c) + (1 / d) + (1 / e)
50 r = 1 / p
60 Print " the equivalent resistance is"; r
70 End

------------------

[Link] a program in Basic to input five resistance and find


equivalent resistance of parallel combination.
Answer Option-2

10 Rem "Resistance in parallel combination of 5 resistances."


15 CLS
20 Dim R(50)
25 RX = 0
30 Print "Enter the 5-resistance value"
40 For I = 1 To 5
50 Input R(I),
60 Next I
70 RX = (1 / R(1)) + (1 / R(2)) + (1 / R(3)) + (1 / R(4)) + (1 / R(5))
80 R = 1 / RX
90 Print "The parallel equivalent resistance value is"; R
100 End
-----------------
[Link] a program in Basic to find first 10 terms of the series
0, 3, 8, 15, 24,36, . . . . .….

10 Rem " FIND SERIES 0,3,8, 15,24,35,.. 10 terms"


15 Cls
20 Dim A(100)
30 For I = 1 To 10
40 A(I) = I * I - 1
50 Next I
55 Print " The 10 terms of the series is.."
60 For I = 1 To 10
70 Print A(I);
80 Next I
90 End
----------------------

[Link] a program in Basic to input days and find year, month


and days
10 Rem "Find Year, Month and Days"
20 Cls
30 Print "we consider 365 days= 1year, 31days=1month"
40 Input "enter the days"; D
50 A = Int(D / 365)
60 A1 = D Mod 365
70 B = Int(A1 / 31)
80 B1 = A1 Mod 31
90 C = B1
100 Print "Year="; A, "Month="; B, "Days="; C
110 End

You might also like