#include <stdio.h>
#include <conio.h>
swap (int*, int*);
main()
{
clrscr();
int i, j;
int arr[10];
int *a;
a=arr;
for ( i = 0; i < 10; i++ )
{
printf (" Enter the number %d : ", i + 1 );
scanf ( "%d", &arr[i] );
}
printf (" Before sorting:\n" );
for ( i = 0; i < 10 ; i++ )
printf ( " %d " , arr[i] );
printf ( "\n" );
for ( i = 0; i < 10; i++ )
for ( j = 0; j < 10 - i - 1; j++ )
if ( * ( arr + j ) > * ( arr + (j + 1) )
swap ( arr + j , arr + (j + 1) );
printf ( "After sorting :\n" );
for ( i = 0 ; i < 10 ; i++)
printf ( "%d ", arr [i] );
printf ( "\n" );
return 0;
}
swap(int *b,int *c )
{
int temp;
temp = *b;
*b = *c;
*c = temp;
return 0;
}
OUTPUT:
Enter the number 1 : 6
Enter the number 2 : 3
Enter the number 3 : 2
Enter the number 4 : 10
Enter the number 5 : 4
Enter the number 6 : 2
Enter the number 7 : 8
Enter the number 8 : 13
Enter the number 9 : 7
Enter the number 10 : 20
Before sorting:
6 3 2 10 4 2 8 13 7 20
After sorting :
2 2 3 4 6 7 8 10 13 20
ALSO READ:
-- Program To Print First Ten(10) Natural Numbers.
-- Program To Print Fibonacci Series Upto 100.
-- Program To Check Whether A Number Is Prime Or Not.
-- Program To Compute The Reverse Of A Number.
-- Program To Print A Semicolon Without Using A Semicolon.
-- Program To Display Function Without Using The Main Function.
-- Program To Print Any Print Statement Without Using Semicolon.
-- Program To Display Its Own Source Code As Its Output.
-- Program To Swap Two Strings Using strcpy() Function.
-- Program to accept a string and print the reverse of the given string.
-- Program To Get IP Address.
-- Program To Accept An Integer & Reverse It.
-- Program To Convert Given Number Of Days To A Measure Of Time Given In Years, Weeks & Days.
-- Program To Illustrate The Concept Of Unions.
-- Program To Find The Size Of A Union.
... Back To C++ Programs Index
... Back To C++ FAQ's Index
... Back To C Programs Index
... Back To C FAQ's Index
... Back To HR Interview Index
ths program is so much complicatd...... ths cn b done in an easy way also
ReplyDeleteYes, you are right. But he is using pointers and which will make better vunderstanding about both sorting and pointer concepts..
Delete