Click here to Skip to main content
15,889,449 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for (i = 0, j = mid; i < arr.Length - 1, j < arr.Length; i++,j++)

is it write ..? if wrong please help me ,

What I have tried:

Swapping of array elements program:
{10,20,30,40,50,60,70,80,90,100};

{60,70,80,90,100,10,20,30,40,50}


static void Main()
{
int i, j, temp,mid;
int[] arr = new int [10] {10,20,30,40,50,60,70,80,90,100};

Console.WriteLine("Array before swapping is : ");
foreach (int a in arr)
{
Console.WriteLine(a + "\t");
}

mid = (arr.Length)/2;
for (i = 0, j = mid; i < arr.Length - 1, j < arr.Length; i++,j++)
{
temp = arr[i];
arr[i] = arr[mid + 1];
arr[mid + 1] = temp;
}

Console.WriteLine("Array before swapping is : ");
foreach (int a in arr)
{
Console.WriteLine(a + "\t");
}

Console.ReadKey();
}
Posted
Updated 30-Jun-16 20:38pm
Comments
JayantaChatterjee 1-Jul-16 2:12am    
check your question tags....
ASP with Console... :-)
ASP is Server Pages, which doesn't have the Console Application...
What are the errors??
where are you stuck ?
manishmishra11june 1-Jul-16 2:13am    
oohh sorry for that, but can you please help me for that question
manishmishra11june 1-Jul-16 2:22am    
did i wrote the syntax in correct manner the
for (i = 0, j = mid; i < arr.Length - 1, j < arr.Length; i++,j++)

erros is coming here, assing for ; expected and , invalid term
JayantaChatterjee 1-Jul-16 2:29am    
You can not add more than one condition in the For Loop..
You need to specify inner loop for that, with the different logic...
manishmishra11june 1-Jul-16 2:32am    
sorry but i saw over internet and books that we can add 2 conditions in a loop at a time... i am just doubtfull about the syntax is correct or not

1 solution

I made this for you:-
C#
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, temp, mid;
            int[] arr = new int[10] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };

            Console.WriteLine("Array before swapping is : ");
            foreach (int a in arr)
            {
                Console.WriteLine(a + "\t");
            }

            mid = (arr.Length) / 2;
            //for (i = 0, j = mid; i < mid ; i++, j++)
            //{
            //    temp = arr[i];
            //    arr[i] = arr[mid];
            //    arr[mid] = temp;
            //}
            j = mid;
            for (i = 0; i < mid; i++)
            {
                temp = arr[i];
                arr[i] = arr[j];
                arr[j++] = temp;
            }
            Console.WriteLine("Array After swapping is : ");
            foreach (int a in arr)
            {
                Console.WriteLine(a + "\t");
            }
           
            Console.ReadKey();
        }
    }
}
 
Share this answer
 

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