Number to String
By
Mubeen Mustafa
Counting Pattern
• 0,1,2,3,4,5,6,7,8,9
• 10,11,12,13,14,15,16,17,18,19
• 10, 20,30,40,50,60,70,80,90
• 100….999
Unit/Single Place
Tens Place ( spoken as ---teen)
Tens Place (spoken as ---ty)
Hundreds Place (Min-Max 3 digit
numbers)
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static int n;
static int temp;
static int i = 0;
static int[] arr = new int[10];
static void ones(int value)//to print numbers in ones
{
switch (value)
{
case 1: Console.Write(" one"); break;
case 2: Console.Write(" Two"); break;
case 3: Console.Write(" three"); break;
case 4: Console.Write(" Four"); break;
case 5: Console.Write(" Five"); break;
case 6: Console.Write(" Six"); break;
case 7: Console.Write(" Seven"); break;
case 8: Console.Write(" Eight"); break;
case 9: Console.Write(" Nine"); break;
default: break;
}
}
static void teens(int value)//to print numbers which are in tens
{
switch (value)
{
case 0: Console.Write("ten"); break;
case 1: Console.Write(" eleven"); break;
case 2: Console.Write(" Twelve"); break;
case 3: Console.Write(" thirteen"); break;
case 4: Console.Write(" Fourteen"); break;
case 5: Console.Write(" Fifteen"); break;
case 6: Console.Write(" Sixteen"); break;
case 7: Console.Write(" Seventeen"); break;
case 8: Console.Write(" Eighteen"); break;
case 9: Console.Write(" Nineteen"); break;
}
}
static void tens(int value)//to print tens values
{
switch (value)
{
case 2: Console.Write(" Twenty"); break;
case 3: Console.Write(" thirty"); break;
case 4: Console.Write(" Forty"); break;
case 5: Console.Write(" Fifty"); break;
case 6: Console.Write(" Sixty"); break;
case 7: Console.Write(" Seventy"); break;
case 8: Console.Write(" Eighty"); break;
case 9: Console.Write(" Ninty"); break;
default: break;
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter a number to convert it into
words");
n = Convert.ToInt32(Console.ReadLine());
do
{
arr[i] = n % 10;
n /= 10;
i++;
} while (n != 0);
wordchange();
Console.ReadLine();
}
static void wordchange()
{
for (temp = i - 1; temp >= 0; temp--)
{
if (temp == 2)//check for the numbers in hundreds
{
if (arr[temp] != 0)
{
ones(arr[temp]);
Console.Write("Hundred");
}
}
else if (temp == 0)//chcek for the numbers in tens and ones
{
if (arr[temp + 1] == 1)
tens(arr[temp]);
else
{
tens(arr[temp + 1]);
ones(arr[temp]);
}
}
}
}
}
}

More Related Content

PDF
Gnuplot 2
PDF
The TensorFlow dance craze
PDF
matplotlib-installatin-interactive-contour-example-guide
PPTX
Project gnuplot
PPTX
Introduction to Java Programming
PDF
14. random numbertabletouchpad
Gnuplot 2
The TensorFlow dance craze
matplotlib-installatin-interactive-contour-example-guide
Project gnuplot
Introduction to Java Programming
14. random numbertabletouchpad

Similar to convert number to string (20)

PPTX
04. Console Input Output
PPT
Csphtp1 15
PPTX
1a. place value
DOCX
Oops pramming with examples
PPT
04 Console input output-
PPTX
Number system 02
DOC
P2 booklet t1( 2014 2015)
PPTX
09. Methods
DOC
Divisibility rules
PPTX
C# basics
DOCX
Write and write line methods
PPT
Strings Arrays
PPTX
Number systems
PPT
number system.ppt
DOCX
C# console applications.docx
PDF
01 number systems-students
PDF
Console programms
PDF
Basic c# cheat sheet
PPT
PPT
04. Console Input Output
Csphtp1 15
1a. place value
Oops pramming with examples
04 Console input output-
Number system 02
P2 booklet t1( 2014 2015)
09. Methods
Divisibility rules
C# basics
Write and write line methods
Strings Arrays
Number systems
number system.ppt
C# console applications.docx
01 number systems-students
Console programms
Basic c# cheat sheet
Ad

More from Mobeen Mustafa (11)

PPTX
Theory of automata
PPT
FInite Automata
PDF
Language
PPT
Mathematical preliminaries in Automata
PPT
Kleene's theorem
PPT
Lect3 ch15-unit2
DOCX
Incremental Model
PPTX
Types of graphics cards
PPTX
Process or preparing effective b.m
PDF
Lecture1
Theory of automata
FInite Automata
Language
Mathematical preliminaries in Automata
Kleene's theorem
Lect3 ch15-unit2
Incremental Model
Types of graphics cards
Process or preparing effective b.m
Lecture1
Ad

Recently uploaded (20)

PPTX
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PDF
The TKT Course. Modules 1, 2, 3.for self study
PPT
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
PPTX
CAPACITY BUILDING PROGRAMME IN ADOLESCENT EDUCATION
PPTX
What’s under the hood: Parsing standardized learning content for AI
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
PDF
Compact First Student's Book Cambridge Official
DOCX
Ibrahim Suliman Mukhtar CV5AUG2025.docx
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PDF
Civil Department's presentation Your score increases as you pick a category
PDF
Farming Based Livelihood Systems English Notes
PDF
Hospital Case Study .architecture design
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
PDF
Everyday Spelling and Grammar by Kathi Wyldeck
PPTX
Macbeth play - analysis .pptx english lit
PDF
M.Tech in Aerospace Engineering | BIT Mesra
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
The TKT Course. Modules 1, 2, 3.for self study
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
CAPACITY BUILDING PROGRAMME IN ADOLESCENT EDUCATION
What’s under the hood: Parsing standardized learning content for AI
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI Syllabus.pdf
Compact First Student's Book Cambridge Official
Ibrahim Suliman Mukhtar CV5AUG2025.docx
Cambridge-Practice-Tests-for-IELTS-12.docx
ACFE CERTIFICATION TRAINING ON LAW.pptx
Civil Department's presentation Your score increases as you pick a category
Farming Based Livelihood Systems English Notes
Hospital Case Study .architecture design
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
Journal of Dental Science - UDMY (2021).pdf
PLASMA AND ITS CONSTITUENTS 123.pptx
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2015).pdf
Everyday Spelling and Grammar by Kathi Wyldeck
Macbeth play - analysis .pptx english lit
M.Tech in Aerospace Engineering | BIT Mesra

convert number to string

  • 2. Counting Pattern • 0,1,2,3,4,5,6,7,8,9 • 10,11,12,13,14,15,16,17,18,19 • 10, 20,30,40,50,60,70,80,90 • 100….999 Unit/Single Place Tens Place ( spoken as ---teen) Tens Place (spoken as ---ty) Hundreds Place (Min-Max 3 digit numbers)
  • 3. Code using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication6 { class Program { static int n; static int temp; static int i = 0; static int[] arr = new int[10]; static void ones(int value)//to print numbers in ones { switch (value) { case 1: Console.Write(" one"); break; case 2: Console.Write(" Two"); break; case 3: Console.Write(" three"); break; case 4: Console.Write(" Four"); break; case 5: Console.Write(" Five"); break; case 6: Console.Write(" Six"); break; case 7: Console.Write(" Seven"); break; case 8: Console.Write(" Eight"); break; case 9: Console.Write(" Nine"); break; default: break; } } static void teens(int value)//to print numbers which are in tens { switch (value) { case 0: Console.Write("ten"); break; case 1: Console.Write(" eleven"); break; case 2: Console.Write(" Twelve"); break; case 3: Console.Write(" thirteen"); break; case 4: Console.Write(" Fourteen"); break; case 5: Console.Write(" Fifteen"); break; case 6: Console.Write(" Sixteen"); break; case 7: Console.Write(" Seventeen"); break; case 8: Console.Write(" Eighteen"); break; case 9: Console.Write(" Nineteen"); break; } } static void tens(int value)//to print tens values { switch (value) {
  • 4. case 2: Console.Write(" Twenty"); break; case 3: Console.Write(" thirty"); break; case 4: Console.Write(" Forty"); break; case 5: Console.Write(" Fifty"); break; case 6: Console.Write(" Sixty"); break; case 7: Console.Write(" Seventy"); break; case 8: Console.Write(" Eighty"); break; case 9: Console.Write(" Ninty"); break; default: break; } } static void Main(string[] args) { Console.WriteLine("Enter a number to convert it into words"); n = Convert.ToInt32(Console.ReadLine()); do { arr[i] = n % 10; n /= 10; i++; } while (n != 0); wordchange(); Console.ReadLine(); } static void wordchange() { for (temp = i - 1; temp >= 0; temp--) { if (temp == 2)//check for the numbers in hundreds { if (arr[temp] != 0) { ones(arr[temp]); Console.Write("Hundred"); } } else if (temp == 0)//chcek for the numbers in tens and ones { if (arr[temp + 1] == 1) tens(arr[temp]); else { tens(arr[temp + 1]); ones(arr[temp]); } } } } } }