.Net Practical 7

Practical : 7
Subject : .Net

Aim : Write a C# code to convert digits to words.

Source Code :

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

namespace dotnet008
{
    class pra7
    {
        static void Main(string[] args)
        {
            int i = 0, num, digit = 0;
            int[] n = new int[20];
            string[] st = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
            Console.Write("Enter number : ");
            num = Convert.ToInt32(Console.ReadLine());
            int len = num.ToString().Length;
            do
            {
                digit = num % 10;
                n[i] = digit;
                i++;
                num = num / 10;
            } while (num > 0);
            for (i = len - 1; i >= 0; i--)
            {
                Console.Write(st[n[i]] + " ");
            }
            Console.ReadKey();
        }
    }
}
Output :

Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment