You are on page 1of 4

01 October 2021

Predefined function:
ASC and CHR
ACS returns the ASCII value of a character.
CHR returns the character of a given ASCII

Qu Write a program to enter a character and display its ASCII value.

Module Module1

Sub Main()
Dim ch As Char
Dim AsciiValue As Integer

Console.WriteLine(" Enter a character")


ch = Console.ReadLine
AsciiValue = Asc(ch)
Console.WriteLine("The ASCII value of the character " & ch & " is " &
AsciiValue)
Console.WriteLine("Press Any Key to continue...")
Console.ReadKey()
End Sub

End Module

Qu2 Write a program to enter an ASCII value and then display its corresponding a character.

Module Module1

Sub Main()
Dim ch As Char
Dim AsciiValue As Integer
Console.WriteLine(" Enter an ASCII value")
AsciiValue = Console.ReadLine
ch = Chr(AsciiValue)
Console.WriteLine("The character of the ASCII value " & AsciiValue & " is " &
ch)
Console.WriteLine("Press Any Key to continue...")
Console.ReadKey()
End Sub

End Module

Qu write a program to enter 100 digits and then output the number of each digit entered.
Dim Digit, index as Integer
Dim Counter(10) as integer

For index = 1 to 100


Do
Console.writeline (“Enter a digit”)
Digit = Console.readline
IF (digit < 0) or (digit > 9) Then
Console.writeline (“ERROR! Must enter a digit. Enter again”)
Endif
Until (digit >=0) and (digit <= 9)
Counter(digit) = counter(digit) + 1
Next
For index = 0 to 9
Console.writeline (“Number of ” & Index & “ is ” & Counter(index)
Next

Qu Write a program to enter 100 integers between 20 and 40 inclusive and


then output the number of each integer entered.

Dim num, index as integer 20 increment counter(0) by 1


Dim counter(21) as integer 21 increment counter(1) by 1
22 increment counter(2) by 1
For index = 1 to 100 23 increment counter(3) by 1
Do
Console.writeline (“Enter a num”)
num = Console.readline
IF (digit < 20) or (digit > 40) Then
Console.writeline (“ERROR! Must enter a number in range 20 to 40. Enter again”)
Endif
Until (num >=20) and (num <= 40)
Counter(num-20) = counter(num-20) + 1
Next
For index = 20 to 40
Console.writeline (“Number of ” & Index & “ is ” & Counter(index-20)
Next

Qu Write a program to enter 100 uppercase alphabets and


then output the number of each uppercase alphabets entered.

Dim ch as char
Dim index as integer
Dim counter(25) as integer

For index = 1 to 100


Do
Console.writeline (“Enter an Upper Case alphabet”)
ch = Console.readline
IF (ch < “A”) or (ch > “Z”) Then
Console.writeline (“ERROR! Must enter uppercase Letter. Enter again”)
Endif
Until (ch >=“A”) AND (ch <= “Z”)
Counter(ASC(ch) - 65 ) = counter(ASC(ch) - 65) + 1
Next
For index = 0 to 25
Console.writeline (“Number of ” & chr(Index + 65) & “ is ” & Counter(index)
Next

You might also like