Programming

C# – ASCii

November 29, 2015

Problem: Create a program to give the ascii code of your inputted word. Separate the consonants and vowel letters.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ascii
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] consonant = new int[20];
            int[] vowel = new int[20];
            int[] str = new int[50];
            int i = 0, j = 0, v = 0, c = 0;

            do
            {
                str[i] = System.Console.Read();
                i++;
            }
            while (i < 50 && str[i - 1] != 13);
            i--;
            for (j = 0; j < i; j++)
            {
                if (str[j] != 32)
                {
                    if (str[j] == 'a' || str[j] == 'e' || str[j] == 'i' || str[j] == 'o' || str[j] == 'u')
                        vowel[v++] = str[j];
                    else
                        consonant[c++] = str[j];
                }
            }
            System.Console.Write("Consonants: ");
            for (i = 0; i < c; i++)
                System.Console.Write("{0}, ", (int)consonant[i]);

            System.Console.Write("\nVowels: ");
            for (i = 0; i < v; i++)
                System.Console.Write("{0}, ", (int)vowel[i]);

            System.Console.ReadKey();
        }
    }
}

Output:

OUtput

OUtput

You Might Also Like...

No Comments

    Leave a Reply