Someone help and explain a project in C++

Good morning how are you all doing? I know your are all busy and I was wondering if someone could help me out here. I need to create a array fo random numbers in C++. I am having a hard time understanding how to do this so anyone is willing to help and explain I will really appreciate it. Thank you
Who is Participating?

Improve company productivity with a Business Account.Sign Up

nonubikConnect With a Mentor Commented:
Here is a sample from MSDN

// crt_rand.c
/* This program seeds the random-number generator
 * with the time, then displays 10 random integers.

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main( void )
   int i;

   /* Seed the random-number generator with current time so that
    * the numbers will be different every time we run.
   srand( (unsigned)time( NULL ) );

   /* Display 10 numbers. */
   for( i = 0;   i < 10;i++ )
      printf( "  %6d\n", rand() );
Sample Output
D_bashamAuthor Commented:
I have  a question though,  I have seen time with 0 instead of NULL what is that all about. Also I see %6 I have seen %N before what is that all about too? Sorry I just really want to understand what I am doing?
NULL is just a macro defined as:
#define NULL ((void *)0)

So basically NULL and 0 is the same.

>printf( "  %6d\n", rand() );
You should take a look at and

The '6' is the width
The width argument is a nonnegative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values

The 'd' specifies an integer data format

The \'n' means that a 'newline' character is added after each number.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

For your array, you should just do

int arrRnd[10];
for( i = 0;   i < 10;i++ )
      arrRnd[i] = rand() ;
D_bashamAuthor Commented:
Thanks for taking the time to help me. I have one more favior. Could you explain the merge sort a little to me. I understand the concept of it but having a tough time starting it. Thanks
A merge sort normal is soved recursively. You have two functions, mergesort und merge.

mergesort divides a given array into 2 parts and calls mergesort again for the left part and the right part.

merge merges two already sorted arrays that are two contigous parts of one array.

so sort an array you have simply to call mergesort passing the array and the array size. By recursion the array is divided into parts till the array size is 1. The merge call of the last recursion then brings two single items in the right order, the merge of last-1 recursion merges pairs, and so on. The last nerge call of the initial call to mergesort finally returns the sorted array.

Have a look to that question if you want to see code:

Regards, Alex

BTW, you should give all points to nonubik as he/she has suffuciently answered your initial question and either open a new question or increase the points of this question before closing it.


Have a look
@Alex: thanx for support ;)
D_bashamAuthor Commented:
Thank you so much nonbuik for all your help. My text book wasn't helping me enough with on how to do this project. Thanks for being a help.

itsmeandnobodyelse, thank you for the direction I ended up finding an example in one of my begining books that helped me too on how to do tha merge sort. That was a tricky one if you haven't done it before. Very, very efficent just a little more complex then a simple bubble sort. Thanks again both you you:)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.