#include<stdio.h>

main()
{
   int array[100], n, c, d, swap;

   printf("Enter number of elements\n");
   scanf("%d", &n);

   printf("Enter %d integers\n", n);

   for ( c = 0 ; c < n ; c++ )
       scanf("%d", &array[c]);

   for ( c = 0 ; c < ( n - 1 ) ; c++ )
   {
      for ( d = 0 ; d < n - c - 1 ; d++ )
      {
          if ( array[d] > array[d+1] ) /* For decreasing order use < */
          {
             swap = array[d];
             array[d] = array[d+1];
             array[d+1] = swap;
          }
      }
   }

   printf("Sorted list in ascending order:\n");

   for ( c = 0 ; c < n ; c++ )
       printf("%d\n", array[c]);

   return 0;
}

my doubt is in this sorting algorithm everything is stored in the array[c] but why they use array[d] can u explain me???

Uh, learn how variables work.

but they did not assign array[c]=array[d]

c and d are just the index of array..

interprete the programme put values of c and d you will undersatnd
And array[c] or array[d] are not diffrent but same variable.
just index changes like array[0],array[1].....

 for ( c = 0 ; c < n ; c++ )
       scanf("%d", &array[c]);

in the beggining c=0 , therefore when reading an integer into array[c] it actually
means you read an integer into the 0 place ( aka array[0] )

after placing a number in the array[0] place, 'c' grows by one (for(....;c++)
and the next number goes into the next array place.

think of c and d as place markers
if you do

int c=0;
int d=0;

if (array[c]==array[d])
    puts("of course they are its like saying array[0]==array[0]");
else
    puts("not sure i'll open the c book and try to figure it out");

puts("thanks anyway");

what output will you get? good luck :O

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.