कंप्यूटर प्रोग्रामिंग/ऐरे/विजुअल बेसिक .नेट
दिखावट
arrays.vb
[सम्पादन | स्रोत सम्पादित करें]' This program uses arrays to display temperature conversion tables
' and temperature as an array subscript to find a given conversion.
Imports System
Public Module Arrays
Sub Main
Dim C() As Double
Dim F() As Double
C = BuildC(100)
F = BuildF(212)
DisplayArray("C", C)
DisplayArray("F", F)
FindTemperature(C, F)
End Sub
Private Function BuildC(Size As Integer) As Double()
Dim C() As Double
Dim Index As Integer
ReDim C(Size)
For Index = 0 To Size
C(Index) = Index * 9 / 5 + 32
Next
Return C
End Function
Private Function BuildF(Size As Integer) As Double()
Dim F() As Double
Dim Index As Integer
ReDim F(Size)
For Index = 0 To Size
F(Index) = (Index - 32) * 5 / 9
Next
Return F
End Function
Private Sub DisplayArray(Name As String, Array() As Double)
Dim Index As Integer
For Index = 0 To Array.Length - 1
Console.WriteLine(Name & "[" & Index & "] = " & Array(Index))
Next
End Sub
Private Sub FindTemperature(C() As Double, F() As Double)
Dim Temp As Integer
Dim Size As Integer
Size = Minimum(C.Length, F.Length)
Do
Console.WriteLine("Enter a temperature between 0 and " & (Size - 1))
Temp = Convert.ToInt32(Console.ReadLine())
Loop While Temp < 0 Or Temp > Size - 1
Console.WriteLine(Temp & "° Celsius is " & C(Temp) & "° Fahrenheit")
Console.WriteLine(Temp & "° Fahrenheit is " & F(Temp) & "° Celsius")
End Sub
Private Function Minimum(Value1 As Integer, Value2 As Integer) As Integer
Dim Result As Integer
If Value1 < Value2 Then
Result = Value1
Else
Result = Value2
End If
Return Result
End Function
End Module
कोशिश करो
[सम्पादन | स्रोत सम्पादित करें]निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।