Hey guys!! can you share some ideas about this program, i tried but its not working.


1. Write a program that inputs a five-digit integer, separates the integer into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in 42339, the program should print:

4 2 3 3 9


hope for a nice reply guys!!!!

Recommended Answers

All 6 Replies

Ok, Can you show us what you have so far?

Ok, Can you show us what you have so far?

My code was not here in this PC ryt now. Im n school. And they disabled usb or cd-rom to transfer our files.

Hope u understand!!

franktly im new to this C#.
Im trying to find some source of it to know it better.

hope u can give some ideas.

Hey guys!! can you share some ideas about this program, i tried but its not working.


1. Write a program that inputs a five-digit integer, separates the integer into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in 42339, the program should print:

4 2 3 3 9


hope for a nice reply guys!!!!

You can use Split() method.........

Think about a string as an array of char and somthing like this:

string intput = "43389";
string output = "";

foreach (char c in intput)
{
    output += c + "   ";
}

Here is a sample validating the user input is of integral value and using the same concept privatevoid mentioned of treated the input as a character array:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace daniweb.console
{
  public static class IntSplit
  {
    public static void Main()
    {
      string input;
      int i;
      do
      {
        Console.Write("Enter your integer value: ");
        input = Console.ReadLine();
      }
      while (string.IsNullOrEmpty(input) || !int.TryParse(input, out i));

      StringBuilder sb = new StringBuilder();
      for (int i1 = 0; i1 < input.Length; i1++)
        sb.Append((i1 == 0 ? string.Empty : " ") + input[i1]);
      Console.WriteLine("Each digit: " + sb.ToString());
      Console.WriteLine(Environment.NewLine);
      Console.WriteLine("Press any key to exit the application.");
      Console.ReadKey();
    }
  }
}

Ok, Can you show us what you have so far?

i will send the code ASAP!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.