# Thread: I don't know how to start, need Help

1. ## I don't know how to start, need Help

use Arrays, functions, loop, and if-else

can someone help me how to start this Code, i don't understand exactly how to implement this code. i don't know how to start. I'm a beginner and this is a beginning class.

Code:
```Complete the following program. You will mainly implement three out of five functions
used in this program!

main()
{

/* Declare three integer arrays as follows */
int a[50], b[70], c[120];

/* Implement a function set_array_rand(int x[], int n)
and call it to generate the values in array a and b
randomly. */
set_array_rand(a, 50);
set_array_rand(b, 70);

/* Using the selection_sort(double x[], int n)
function we implemented in class, sort the elements in
a and b arrays. */
selection_sort(a, 50);
selection_sort(b, 70);

/* Implement a MERGE function and call it as follows
to merge the values in arrays a and b into array c
such that the values in c will be sorted after merging
*/
merge_sort(a, 50, b, 70, c, 120);

/* Print the values in array c */
print_array(c, 120);
}

void set_array_rand(int x[], int n)
{

/* Randomly generate elements of x array */
for(int i=0; i< n; i++)
x[i] = rand_int(30, 100);

}

int rand_int(int a,int b)
{

return rand()%(b-a+1) + a;
}

void selection_sort(int x[], int n)
{

}

void merge_sort(int a[], int na, int b[], int nb, int c[],
int nc)
{

/* merge the values in a and b into c while keeping
the values sorted. For example, suppose we have the
following arrays a = { 3, 7, 9, 12} and b = {4, 5, 10}
When we merge these two arrays, we will get
c = {3, 4, 5, 7, 9, 10, 12} */

}

void print_array(int x[], int n)
{

}```

2. Do a wikipedia search for the various search algorithms you have to implement. Take your best guess at the implementation, try it out, and compare the result with what you expected. If you run into any problems, let us know, but you need to try this yourself first.

3. Originally Posted by sean
Do a wikipedia search for the various search algorithms you have to implement. Take your best guess at the implementation, try it out, and compare the result with what you expected. If you run into any problems, let us know, but you need to try this yourself first.
i did a research and read about arrays, saw some examples and i tried the first two where it says "your code"
but if you could explain me a little bit of how to get this going, i will appreaciatted.

Code:
```main()
{
/* Declare three integer arrays as follows */
int a[50], b[70], c[120];

/* Implement a function set_array_rand(int x[], int n)
and call it to generate the values in array a and b
randomly. */

set_array_rand(a, 50);
set_array_rand(b, 70);

/* Using the selection_sort(double x[], int n)
function we implemented in class, sort the elements in
a and b arrays. */

selection_sort(a, 50);
selection_sort(b, 70);

/* Implement a MERGE function and call it as follows
to merge the values in arrays a and b into array c
such that the values in c will be sorted after merging
*/
merge_sort(a, 50, b, 70, c, 120);

/* Print the values in array c */
print_array(c, 120);
}

void set_array_rand(int x[], int n)
{

/* Randomly generate elements of x array */
for(int i=0; i< n; i++)
x[i] = rand_int(30, 100);
}
int rand_int(int a,int b)
{
return rand()%(b-a+1) + a;
}
void selection_sort(int x[], int n)
{

for (i=0; i<100; i++)
data[i] = (rand() % 100) + 30;

}

void merge_sort(int a[], int na, int b[], int nb, int c[],
int nc)
{
/* merge the values in a and b into c while keeping
the values sorted. For example, suppose we have the
following arrays a = { 3, 7, 9, 12} and b = {4, 5, 10}
When we merge these two arrays, we will get
c = {3, 4, 5, 7, 9, 10, 12} */

int a[]={3, 7, 9, 12,};
int b[]={4,5,10}

int a, b, count;

for(a = 0; a < 12;  i++){
count = 1;

for(b = 0; b < 10;  j++){
if (x[a] == x[b]) count++;
}
printf(“%d %d \n”, x[a], count);
}

}

void print_array(int x[], int n)
{

}```

4. Start your own program and go step by step, implementing each "YOUR CODE" segment one at a time.

Start with a simple "main()" that calls "set_array_rand(a, 50)", get that working, and so on. There is a lot that is done for you, you just need to fill in the blanks. Write down on paper in plain english (or what ever language) what the program currently does and compare to what it needs to do and fill in the blanks.

It seems to me that any more "help" at this point would really be just writing it for you.

Give it a try and if you have specific questions about YOUR code post it.

5. Code:
`/* my reply */`

6. I suppose to should have learnt by now about array and sorting algorithm. Since you proferssor had already meantioned it in the assignment

Code:
`we implemented in class`
Anyways, start from here. Write a simple code to delare an array of 10 elements and populate it with the random values ??

Here is a templete for you.

Code:
```#include <stdio.h>
#include <time.h>

int main()
{
int array[ < fill the no. of elements > ]
/* Declare more variables if needed */

srand(time(NULL));

for( < use for loop to step through the array > )
array[ index ] = random value;

for( < use for loop to step through the array > )
printf array [index]

getchar();
return 0;
}```