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

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.ppt
Mahyuddin8
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
Tanzeel Ahmad
 
PSI 3 Integration
PSI 3 IntegrationPSI 3 Integration
PSI 3 Integration
Joseph Asencio
 
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
arshin9
 
Process management
Process managementProcess management
Process management
Utkarsh Kulshrestha
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
C++ 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
SadhikaPolamarasetti1
 
Listing for MyNumberFormats
Listing for MyNumberFormatsListing for MyNumberFormats
Listing for MyNumberFormats
Derek 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.pdf
SHASHIKANT346021
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
ShashikantSathe3
 
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-loops
James 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 Conversion
Svetlin Nakov
 
Loops
LoopsLoops
Loops
Kamran
 
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
FashionColZone
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
Fraz Bakhsh
 
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
Rahul04August
 

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

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

How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 

Recently uploaded (20)

How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 

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