SlideShare a Scribd company logo
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)

PPT
ch05-program-logic-indefinite-loops.ppt
PPTX
130707833146508191
PDF
Programming Fundamentals presentation slide
PDF
PSI 3 Integration
PDF
Write a java program to randomly generate the following sets of data.pdf
PPTX
Process management
PPTX
CPP Homework Help
PDF
Computational Problem Solving 004 (1).pptx (1).pdf
PDF
Listing for MyNumberFormats
PPT
09-ch04-1-scanner class in java with explainiation
PDF
Natural Language Processing (NLP)
PDF
LECTURE 3 LOOPS, ARRAYS.pdf
PPT
Whats new in_csharp4
PDF
LECTURE 3 LOOPS, ARRAYS.pdf
PPTX
C programming language tutorial
PPTX
Chapter 5 Loops by z al saeddddddddddddddddddddddddddddddddddd
PPT
Ch02 primitive-data-definite-loops
PPT
C Sharp Jn (3)
PPTX
Java Foundations: Data Types and Type Conversion
PPT
Loops
ch05-program-logic-indefinite-loops.ppt
130707833146508191
Programming Fundamentals presentation slide
PSI 3 Integration
Write a java program to randomly generate the following sets of data.pdf
Process management
CPP Homework Help
Computational Problem Solving 004 (1).pptx (1).pdf
Listing for MyNumberFormats
09-ch04-1-scanner class in java with explainiation
Natural Language Processing (NLP)
LECTURE 3 LOOPS, ARRAYS.pdf
Whats new in_csharp4
LECTURE 3 LOOPS, ARRAYS.pdf
C programming language tutorial
Chapter 5 Loops by z al saeddddddddddddddddddddddddddddddddddd
Ch02 primitive-data-definite-loops
C Sharp Jn (3)
Java Foundations: Data Types and Type Conversion
Loops
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)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Computing-Curriculum for Schools in Ghana
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Structure & Organelles in detailed.
PPTX
master seminar digital applications in india
PPTX
Lesson notes of climatology university.
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Computing-Curriculum for Schools in Ghana
Weekly quiz Compilation Jan -July 25.pdf
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Structure & Organelles in detailed.
master seminar digital applications in india
Lesson notes of climatology university.
VCE English Exam - Section C Student Revision Booklet
Anesthesia in Laparoscopic Surgery in India
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Classroom Observation Tools for Teachers
202450812 BayCHI UCSC-SV 20250812 v17.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

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]); } } } } } }