#include
#include
#define MAX_ARY 10
void merge_sort(int x[], int end, int start);
int main(void) {
int ary[MAX_ARY];
int j = 0;
printf("\n\nEnter the elements to be sorted: \n");
for(j=0;j scanf("%d",&ary[j]);
/* array before mergesort */
printf("Before :");
for(j = 0; j < MAX_ARY; j++)
printf(" %d", ary[j]);
printf("\n");
merge_sort(ary, 0, MAX_ARY - 1);
/* array after mergesort */
printf("After Merge Sort :");
for(j = 0; j < MAX_ARY; j++)
printf(" %d", ary[j]);
printf("\n");
getch();
}
/* Method to implement Merge Sort*/
void merge_sort(int x[], int end, int start) {
int j = 0;
const int size = start - end + 1;
int mid = 0;
int mrg1 = 0;
int mrg2 = 0;
int executing[MAX_ARY];
if(end == start)
return;
mid = (end + start) / 2;
merge_sort(x, end, mid);
merge_sort(x, mid + 1, start);
for(j = 0; j < size; j++)
executing[j] = x[end + j];
mrg1 = 0;
mrg2 = mid - end + 1;
for(j = 0; j < size; j++) {
if(mrg2 <= start - end)
if(mrg1 <= mid - end)
if(executing[mrg1] > executing[mrg2])
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
else
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
}
}
;j++)>
it is a step by step program written in simple English for our understanding
You mean 'count' as variable-name? It is optional.
Reference:cprogramming-bd.com/c_page1.aspx#simpleinterest
i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?
try making yourself..hope it will be useful ofr you!
Well, this is a very open question, please be specific, I will try try to answer this as well, a simple c language program can be any thing from printing your name on the screen to printing some patterns using symbols, or making a small game, or a simple calculator program. you can a clearer picture of what can be a simple c language program here:
it is a step by step program written in simple English for our understanding
Not used
#include <stdio.h> #include <stdlib.h> #define MAXARRAY 10 void mergesort(int a[], int low, int high); int main(void) { int array[MAXARRAY]; int i = 0; /* load some random values into the array */ for(i = 0; i < MAXARRAY; i++) array[i] = rand() % 100; /* array before mergesort */ printf("Before :"); for(i = 0; i < MAXARRAY; i++) printf(" %d", array[i]); printf("\n"); mergesort(array, 0, MAXARRAY - 1); /* array after mergesort */ printf("Mergesort :"); for(i = 0; i < MAXARRAY; i++) printf(" %d", array[i]); printf("\n"); return 0; } void mergesort(int a[], int low, int high) { int i = 0; int length = high - low + 1; int pivot = 0; int merge1 = 0; int merge2 = 0; int working[length]; if(low == high) return; pivot = (low + high) / 2; mergesort(a, low, pivot); mergesort(a, pivot + 1, high); for(i = 0; i < length; i++) working[i] = a[low + i]; merge1 = 0; merge2 = pivot - low + 1; for(i = 0; i < length; i++) { if(merge2 <= high - low) if(merge1 <= pivot - low) if(working[merge1] > working[merge2]) a[i + low] = working[merge2++]; else a[i + low] = working[merge1++]; else a[i + low] = working[merge2++]; else a[i + low] = working[merge1++]; } }
You mean 'count' as variable-name? It is optional.
Reference:cprogramming-bd.com/c_page1.aspx#simpleinterest
Write a simple program in finding roots x^3-6x^2+11x-6.1=0
i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?
int main (void) { puts ("Hello, world"); return 0; }
try making yourself..hope it will be useful ofr you!
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
the features of a C program