In the code given below m not getting ,
1) wht he has written in "Console.WriteLine("Enter Value p[{0}]:", i);" wht is P[{0}] n wht is i ,,,,,

2)
Console.WriteLine("c[{0}]={1}, c[{2}]={3}", i, c, j, c[j]);
wht is c[{0}] = {1},c[{2}]={3} " , i , c

``````using System;
class AscendingBubbleSort
{
public static void Main()
{
int i = 0,j = 0,t = 0;
int []c=new int[20];
for(i=0;i<20;i++)
{
Console.WriteLine("Enter Value p[{0}]:", i);
}
// Sorting: Bubble Sort
for(i=0;i<20;i++)
{
for(j=i+1;j<20;j++)
{
if(c[i]>c[j])
{
Console.WriteLine("c[{0}]={1}, c[{2}]={3}", i, c[i], j, c[j]);
t=c[i];
c[i]=c[j];
c[j]=t;
}
}
}
Console.WriteLine("Here comes the sorted array:");
// Print the contents of the sorted array
for(i=0;i<20;i++)
{
Console.WriteLine ("c[{0}]={1}", i, c[i]);
}
}
}``````

In Console.WriteLine, {0} acts as a placholder for a value to be put in a string.
So Console.WriteLine("Enter Value p[{0}]:", i); (Let i in the for loop be 3) would print out: Enter Value p[ 3 ]:

I would prefer to change this to
Console.WriteLine("Enter Value Number {0} :", i);
which in the same case( i = 3 ) would print out: Enter Value Number 3 :

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.