SlideShare a Scribd company logo
1 of 4
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

Similar to convert number to string

ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptMahyuddin8
 
Write a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdfWrite a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdfarshin9
 
Computational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdfComputational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdfSadhikaPolamarasetti1
 
Listing for MyNumberFormats
Listing for MyNumberFormatsListing for MyNumberFormats
Listing for MyNumberFormatsDerek Dhammaloka
 
Natural Language Processing (NLP)
Natural Language Processing (NLP)Natural Language Processing (NLP)
Natural Language Processing (NLP)Hichem Felouat
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfSHASHIKANT346021
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfShashikantSathe3
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Ch02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsCh02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsJames Brotsos
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)jahanullah
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionSvetlin Nakov
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfFashionColZone
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfRahul04August
 

Similar to convert number to string (20)

ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
PSI 3 Integration
PSI 3 IntegrationPSI 3 Integration
PSI 3 Integration
 
Write a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdfWrite a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdf
 
Process management
Process managementProcess management
Process management
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Computational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdfComputational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdf
 
Listing for MyNumberFormats
Listing for MyNumberFormatsListing for MyNumberFormats
Listing for MyNumberFormats
 
Natural Language Processing (NLP)
Natural Language Processing (NLP)Natural Language Processing (NLP)
Natural Language Processing (NLP)
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Ch02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsCh02 primitive-data-definite-loops
Ch02 primitive-data-definite-loops
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
Loops
LoopsLoops
Loops
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 

More from Mobeen Mustafa

More from Mobeen Mustafa (11)

Theory of automata
Theory of automataTheory of automata
Theory of automata
 
FInite Automata
FInite AutomataFInite Automata
FInite Automata
 
Language
LanguageLanguage
Language
 
Mathematical preliminaries in Automata
Mathematical preliminaries in AutomataMathematical preliminaries in Automata
Mathematical preliminaries in Automata
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Lect3 ch15-unit2
Lect3 ch15-unit2Lect3 ch15-unit2
Lect3 ch15-unit2
 
Incremental Model
Incremental ModelIncremental Model
Incremental Model
 
RAD
RADRAD
RAD
 
Types of graphics cards
Types of graphics cardsTypes of graphics cards
Types of graphics cards
 
Process or preparing effective b.m
Process or preparing effective b.mProcess or preparing effective b.m
Process or preparing effective b.m
 
Lecture1
Lecture1Lecture1
Lecture1
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

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