Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi , its my program which doing sort .... in need enter input 10 numbers in a line ... how is it possible ... many thanks for ur helping :)
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int [] a = new int [10];
            int i,j,t;
            Console.WriteLine("Enter 10 numbers Before Sort= ");

            for (i = 0; i < 10; i++)
                a[i] = Convert.ToInt32(Console.ReadLine());   //here i need help plz??
          for (i = 0; i < 10; i++)
                for (j = 0; j < 9; j++)
                {
                    if (a[j] < a[j + 1])
                    {
                        t = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = t;
                    
                    }
                        
                    }
            Console.Write("After Sort = ");
            for (i = 0; i < 10; i++)
                Console.Write(a[i] + " , " );


            Console.ReadLine();
        }
    }
}
Posted
Comments
[no name] 14-Jul-13 13:28pm    
"here i need help plz?"... okay.... and what kind of help is it that you need?
Lida Zareian 14-Jul-13 13:32pm    
how can i enter some numbers by console.readline() in a line like "5,6,7,8,..." not type any numbers in seprate line like "5
6
7
8 " ?



[no name] 14-Jul-13 13:33pm    
Well get rid of the for loop and call ReadLine once. You can type all of your number in all at the same time.

1 solution

Hi
You must use from Read() instead of ReadLine().

for (i = 0; i < 10; i++)
     a[i] = Convert.ToInt32(Console.Read());   //here i need help plz??


Now, You can enter 10 numbers in bellow structure and enter Enter Key in end of list.
1 2 3 4 5 6 7 8 9 10 Now Press Enter

I hope It's helpful for you
 
Share this answer
 
Comments
Lida Zareian 14-Jul-13 13:40pm    
so helpful .... many thanks friend :)
Reza Alipour Fard 14-Jul-13 14:06pm    
Welcome, I hope you will be success in your life. Best Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900