Saturday 21 September 2013

Small Solution or Small part of Splitting Array! C Sharp

So this is Something Related to the Post "Array Splitter" It is not yet completed but i just figure out few things like this one! A small portion of this problem has been done so far using C SHARP Can you guys suggest me something better or something good for the this Problem?  WE are getting inputs from user and the size of array as well from User. Hope you like it! WE have to Finally do this thing at the end!



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

namespace Testarray
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = 0;
            Console.WriteLine("Please enter the size of array ");
            size=int.Parse(Console.ReadLine());
            int size1 = size;
            Console.WriteLine("Size= " +size);
            int []arr= new int[size];
            int mid = (size / 2);
         
            int mid2 = (size / 2);
            Console.WriteLine("Now Please enter elements");
            for (int i = 0; i < size;i++ )
            {
                arr[i]=int.Parse(Console.ReadLine());
            }
            for (int j = 0; j < size +4;j++ )
            {

                int[] subarr1 = new int[size / 2];
                int[] subarr2 = new int[size / 2];

                Array.Copy(arr, 0, subarr1, 0, mid);
                Console.WriteLine("mid = " + mid);
                Console.WriteLine("size = " + size);
       
                Array.Copy(arr, mid, subarr2, 0, mid);
                Console.Write("-----------------------");
                Console.Write(Environment.NewLine);
                Console.Write("Array: ");
                for (int i = 0; i < size; i++)
                {
                    Console.Write(arr[i] + " , ");

                }
                Console.Write(Environment.NewLine);
                Console.Write("Left: ");
                for (int i = 0; i < subarr1.Length; i++)
                {
                    Console.Write(subarr1[i] + " , ");

                }
                Console.Write(Environment.NewLine);
                Console.Write("Right: ");
                for (int i = 0; i < subarr2.Length; i++)
                {
                    Console.Write(subarr2[i] + " , ");

                }
                Console.Write(Environment.NewLine);
                Console.Write("-----------------------");
              size = size / 2;
              mid = mid / 2;
           
            }
   
        }
    }
}

No comments:

Post a Comment

Please add sensible comments! Please don't spam otherwise Comment will not be published. Share your Thoughts!