Posts

Reverse the Input string

Module Module1 Sub Main() 'program to reverse the input string 'declaring the variables Dim Index As Integer Dim temp, reverse, inputed_string As String Console.WriteLine("Enter the String") inputed_string = Console.ReadLine() reverse = "" Index = Len(inputed_string) While Index 0 temp = Mid(inputed_string, Index, 1) reverse = reverse & temp Index = Index - 1 End While Console.WriteLine("The reversed string is =" & " " & reverse) Console.ReadKey() End Sub End Module

Print the factorial value of an input number

Module Module1 Sub main() 'program to print the factorial value of a input number 'declaring the datatypes Dim num, factorial As Integer 'initializing the value of factorial factorial = 1 'entry of the number Console.WriteLine("Enter the number whose factorial value you want to be generated ") num = Console.ReadLine 'start of the while loop to calculate the factorial value of the input number While num <> 0 factorial = factorial * num num = num - 1 End While 'generating the output of the factorial value Console.WriteLine("The factorial value of the number you entered is " & factorial) Console.ReadLine() ' this line of code holds the screen so that you can see the output End Sub End Module

Reverse the input number and print it

Module Module1 Sub main() 'declaring the datatypes Dim reverse, temp As Integer Dim num As Single 'input the number to be reversed Console.WriteLine("Enter the number to be reversed") num = Console.ReadLine temp = 0 reverse = 0 'start of the while loop While num 0 temp = num Mod 10 reverse = reverse * 10 + temp num = num \ 10 End While 'printing the number after reversing Console.WriteLine(reverse) Console.ReadLine() ' this line of code holds the screen so that you can see the output End Sub End Module

Print Greatest Number out of 3 numbers

Module Module1 Sub Main() Dim num1, num2, num3 As Integer Console.WriteLine("Enter the first number") num1 = Console.ReadLine Console.WriteLine("Enter the second number") num2 = Console.ReadLine Console.WriteLine("Enter the third number") num3 = Console.ReadLine If num1 > num2 And num1 > num3 Then Console.WriteLine(num1 & " is the greatest number") ElseIf num2 > num1 And num2 > num3 Then Console.WriteLine(num2 & " is the greatest number") ElseIf num1 = num2 And num2 = num3 Then Console.WriteLine("Oops ! you have enetered a number thrice. So ! no greater number found") Else Console.WriteLine(num3 & " is the greatest number") End If Console.ReadKey() End Sub End Module

Greatest of two numbers

Module Module1 Sub Main() 'This program checks the greatest number ans shows equal if input numbers are equal. Dim num1, num2 As Integer 'declaring the numbers Console.WriteLine("Enter the first number") 'asking to enter the first number num1 = Console.ReadLine Console.WriteLine("Enter second second number") ' asking to enter the second number num2 = Console.ReadLine 'if conditional If num1 > num2 Then Console.WriteLine(num1 & " is the greatest number.") ElseIf num1 = num2 Then Console.WriteLine("Oops ! you have entered the same number twice") Else Console.WriteLine(num2 & " is the greatest number") End If Console.ReadLine() End Sub End Module

Sum of two numbers

Module Module1 Sub Main() Dim number1 As Integer Dim number2 As Integer Dim sum As Integer 'declaration above can also be defined in a single line instead of three lines as 'Dim number1, number2,sum as Integer 'We can separate them by comma as they share the common data-type Console.WriteLine("Enter the first number") number1 = Console.ReadLine Console.WriteLine("Enter the second number") number2 = Console.ReadLine sum = number1 + number2 Console.WriteLine("The sum of the two numbers is " & sum) Console.ReadKey() End Sub End Module

Program to enter value into the array and print

Module Module1 Sub Main() 'program to input value into array and print it out Dim arr(5) As Integer 'assigning array with integer in it Dim index As Integer 'assigning the counter to be used in the loop Console.WriteLine("Enter the values into the array") For index = 1 To 5 arr(index) = Console.ReadLine Next Console.WriteLine("The elements inside the aaray are: ") For index = 1 To 5 Console.Write(arr(index) & " ") Next Console.ReadKey() ' this line of the code holds the window to see the output End Sub End Module