Tech
Forums
Jobs
Books
Events
Live
Learn
More
Training
Interviews
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
6
Reply
how to handle an IndexOutOfRangeException in C#
Jay Lopez
Sep 21 2016 12:14 AM
809
Reply
using System;
namespace Project1
{
class Project1
{
//Main method begins execution of C# app
static void Main(string[] args)
{
int number;//declare number variable
int[] numberDigits = new int[5];//declare array with 5 digits
int i = 4;//counter
//prompt user and reads number
Console.Write("Enter five digit integer:");
number = Convert.ToInt32(Console.ReadLine());
while(number > 0)
{
int digit = number % 10; //extract last digit
numberDigits[i] = digit;
number = number / 10;//divide by 10 to extract next digit
i--;
}
foreach (int digit in numberDigits) Console.Write("{0} ", digit);
Console.WriteLine();
Console.ReadKey();
}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
6
)
Next Recommended Forum
How to varbinary convert in string for mvc
List View Like Android application in C#