Windows Console program to print 1- 10 digits and some specific text for 4th digit using C#

Last Reply on Jul 04, 2013 06:20 AM By ashusingh

Posted on Jul 04, 2013 05:47 AM

hi all,

 

i have a few douts am trying ascending order program using c#.

actually i done this program by the  given below output of ascending order

output:

1 2 3 4 5 6 7 8 9 10

my question is :

i need to display the message the one who is reach 4 in the order of output which i mentioned above.

my message should be like this (" you have been reached 4th position of ascending order")

after getting the 4 th postions the code again will start execute the reamining order which means 5th,6th,7th,8th,9th and 10th

 

my expected output is:

1

2

3

(" you have been reached 4th position of ascending order")

5

6

7

8

9

10

 

please find out my code below and were i alter my code below. please let me know,advice are very appreciable

my code is:

 

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
         while(i<10)
            {
             
                
                i = i + 1;
                Console.WriteLine(i);
                Console.ReadLine();

               
            }
        }
    }
}

 

thanks in advance..

Posted on Jul 04, 2013 06:20 AM

Hi @ stellusmca

Try the following sample.

 class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <=10; i++)
            {                
                if (i == 4)
                {
                    Console.WriteLine("you have been reached 4th position of ascending order");
                    continue;
                }
                Console.WriteLine(i.ToString());
            }
            Console.ReadLine();
        }
    }

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html