Correct formatting available here - http://pastebin.com/m2e947939 #include // The numbers we want to sort, need at least two int sort_size = 5; int sort_array[5] = { 1, 5, 2, 4, 3 }; int main() { int sorted = 0; int x; while( sorted != 1 ) { for( x = 0, sorted = 1; x != ( sort_size - 1 ); x++ ) { if( sort_array[x] > sort_array[x + 1] ) { // We are not sorted sorted = 0; // Swap sort_array[x] ^= sort_array[x + 1]; sort_array[x + 1] ^= sort_array[x]; sort_array[x] ^= sort_array[x + 1]; } } } printf( "And the numbers are...\n" ); for( x = 0; x < sort_size; x++ ) { printf( "%d\n", sort_array[x] ); } return 0; }
Assume your numbers are into an array. Then write any user-defined function implementing any kind of sorting. I am giving example of bubble sort.void bubble(int a[],int n){int i,j,t;for(i=n-2;i>=0;i--){for(j=0;ja[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}}}}
types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort
Any type you want to write. C does not provide sorting routines natively; you have to either use a library routine or write something. Some library implementations are based on quicksort or heapsort but, again, that is not a C (or C++) thing - it is a run-time library thing.
Write a function that print a triangle of stars.
No. At minimum, you need to provide a main() function.
Into the source program.
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
#include<
void mynullfunction () {;}
bubble_sort (int N, int *A) { int i; swap = 1; while (swap) { swap = 0; for (i=0; i<N-1; ++i) { if (A[i] > A[i+1]) { swap = 1; A[i] ^= A[i+1]; A[i+1] ^= A[i]; A[i] ^= A[i+1]; } } } }
I don't think its possible. Every C++ program must at least have the main function.
Use the tolower() function in the C standard library.