# Thread: Can any one tell me how to make this prgram?

1. ## Can any one tell me how to make this prgram?

Write a program to merge two unsorted 1D
order.

For example:

Input:

double arrays in descending

arr1

8

arr2

9

arr3

9

4

0

2

7

6

5

8

7

6

1

3

5

4

Output:

Note: You need to define the following functions:

void inputarray(int size, double* array);
This function should prompt the user for input and hence input all array elements from the
user.

void printarray(int size, double* array);
This function should print all array elements.

void sortarray(int size, double * array, char order);
This function should sort the array which will be given as the first argument. The second
argument will be ‘A’ or ‘D’ to specify ascending or descending, respectively.

void mergeandsortarray(int size1, double* arr1, int size2, double* arr2, double* arr3);

This function should merge the sorted arrays arr1 and arr2 which will be given as the first and
second arguments. The third argument, arr3, will be the array obviously having the size of array
being the sum of the sizes of the first two arrays and will store the two arrays in merged and
ordered form. Note that your function call to this function must pass the sorted arrays arr1 and
arr2 and then simply merge them. Note that you must NOT use the naïve or simple algorithm
which would copy the two arrays into arr3 and then sort arr3!

Code:
```#include <yourIncludefile.h>

int main(void) {
//other code here

return 0;
}```
More functions down here. You have a list of them, by name, and telling you what parameters they need. The whole prototype is right there! You can copy and paste!

This is the part of the assignment where you have to step up and get it all started. If you get stuck, post up what you have, and tell us what has you stumped.

Don't wait around for someone to start your program for you. The above is all you'll get (and that's more than most). We don't start programs for people. (99% of the time).

Get organized, and get cracking. These kinds of assignments always take a good deal longer than you'd think because the requirements are rather long and have lots of details to be dealt with.

3. well thanks for such advice.. but i am not asking you to make a program for me... i just need your help.. I m new to dynamic arrays..... I need help to understand the logic if any one can help..

4. Originally Posted by fredsilvester93
I m new to dynamic arrays..... I need help to understand the logic if any one can help..
Dynamically allocate your array... with malloc.. calloc... or whatever you like.
If you need your array's size to change when necessary, just realloc it with the necessary amount of memory.
(Or realloc it to...say double the size when you're out of space...that will/may(I'm not sure) improve performance... )

5. I did not find the tutorial on dynamic arrays, so I'm posting up a sample program that uses one 2D array.

It doesn't use realloc(), but that is something I very seldom need to use.

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)  {

int **mat; // Pointer to pointer
int rows, cols, i, j;
printf("How many rows you want ");
scanf("%d", &rows);
//rows = 10;
//cols = 10;
mat = malloc(rows*sizeof(int*));        // array of number of rows

printf("How many cols ");
scanf("%d", &cols);
for (i=0; i<rows; i++) {                // for each row ...
mat[i] = malloc(cols * sizeof(int)); // add these many cols
}
for (i = 0; i<rows; i++) {
for (j = 0; j<cols; j++) {
mat[i][j] = (i+1) * (j+1);
printf("%4d ", mat[i][j]);         //these two print lines
//printf("%4d ", *(*(mat+i)+j));  //do the same thing
}
putchar('\n');
}

printf("\n\n");
return 0;
}```

I did not find the tutorial on dynamic arrays, so I'm posting up a sample program that uses one 2D array.

It doesn't use realloc(), but that is something I very seldom need to use.

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)  {

int **mat; // Pointer to pointer
int rows, cols, i, j;
printf("How many rows you want ");
scanf("%d", &rows);
//rows = 10;
//cols = 10;
mat = malloc(rows*sizeof(int*));        // array of number of rows

printf("How many cols ");
scanf("%d", &cols);
for (i=0; i<rows; i++) {                // for each row ...
mat[i] = malloc(cols * sizeof(int)); // add these many cols
}
for (i = 0; i<rows; i++) {
for (j = 0; j<cols; j++) {
mat[i][j] = (i+1) * (j+1);
printf("%4d ", mat[i][j]);         //these two print lines
//printf("%4d ", *(*(mat+i)+j));  //do the same thing
}
putchar('\n');
}

printf("\n\n");
return 0;
}```
Does dynamic mean user-specified or changeable on demand ?
..I thought the later.

7. Either or both, imo. You have to have it before you can change it, was my idea here.

8. Originally Posted by manasij7479
Does dynamic mean user-specified or changeable on demand ?
..I thought the later.
I'd vote for "Not fixed size"...

Altough I might be persuaded to flip over to "Created at runtime" if the right candidate came along.