i have written this code which s follows:
and my output is
the sorted array is: 8236 8238 8240 8242 8244
i also searched from net and i got dis code
and the output to this code is coming correct
kindly explain the problem
thank you
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5]={4,3,5,2,1};
int i,k,j,temp;
clrscr();
for(j=0;j<4;j++)
{
for(k=j+1;k<5;k++)
{
if(arr[j]>arr[k])
{
temp=arr[j];
arr[j]=arr[k];
arr[k]=temp;
}
}
}
printf("\nThe sorted array is: ");
for(i=0;i<5;i++)
printf("%d\t",&arr[i]);
}
the sorted array is: 8236 8238 8240 8242 8244
i also searched from net and i got dis code
Code:
#include "stdio.h"
void main( )
{
int arr[5] = { 25, 17, 31, 13, 2 } ;
int i, j, temp ;
for ( i = 0 ; i <= 3 ; i++ )
{
for ( j = i + 1 ; j <= 4 ; j++ )
{
if ( arr[i] > arr[j] )
{
temp = arr[i] ;
arr[i] = arr[j] ;
arr[j] = temp ;
}
}
}
printf ( "\n\nArray after sorting:\n") ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;
}
kindly explain the problem
thank you
Comment