hello i am new beginner ,
please help me to split the integer which is user defined......
for example if user enters :(123456)
then
output should be : 1
2
3
4
5
6
*** without using ArrayList
Thanks.
Loading
Kirtan PatelPosted Feb 7, 2010, 2:41 PM
Here is what you want
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Number :");
string Number = Console.ReadLine();
Console.WriteLine("----------Printng Number ----------");
foreach (char c in Number.ToCharArray())
{
Console.WriteLine(c.ToString());
}
Console.ReadKey();
}
}
Lalit MPosted Feb 7, 2010, 11:54 AM
----------------------------
theLizardPosted Jan 20, 2010, 1:27 AM
I would have done it in much the same way as you showed, I guess what I was hinting at was (for the benefit of arun) the fact that it is ok to use an array of some sort to achieve a result and telling a student that they cannot use an ArrayList is pretty silly to me. :}
Sam HobbsPosted Jan 19, 2010, 11:17 PM
So the way I might do it if the data is an integer, not a string, is to divide by successively decreasing powers of ten, then round down of course, then multiply the result by the corresponding power of ten in order to subtract that from the integer so that the next power of ten produces a one-digit result. I hope araun understands that; since this is a class assignment, I won't do the code but I won't complain if someone else does.
theLizardPosted Jan 19, 2010, 8:20 PM
Technically string s is an array of chars and an array list is an array of say, objects which can be an array of chars and arun does not want to use arrays so technically speaking an integer cannot be split as he/she wants without an array of somethings.
I am being funny or silly whichever way you want to look at it. :}
Sam HobbsPosted Jan 19, 2010, 4:53 PM
foreach (char c in s)
Console.WriteLine(c);