Thread: One last problem! Displaying random numbers in INCREASING order!

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    39

    One last problem! Displaying random numbers in INCREASING order!

    Hello,

    I could not find my previous thread for this question and the code was updated a bit. Let me be as specific as possible with instructions:


    My task is to generate 100 random numbers, assign them to an array and then print all of the numbers (WITH NO DUPLICATES) in increasing order.


    I'm starting from the very beginning because I feel as though I confused myself working ahead without knowledge or a guide on how to start. I haven't learned bubble sorting in my class, so I don't know if I can use that.

    Here is the basic structure I'm starting with and hoping to build with your help.

    Code:
     
    
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    
    
    int main(void)
    {
    
    
    
    
    int randNum;
    int myArray[100];
    int i;
    srand((int)time(0)); // Seeds Random Numbers
     
     
      for(i=99; i>0; i--)
      {
    	  randNum = rand()%20 + 1;
    	  printf("%d\n", randNum);
    	  myArray[i] = randNum;
    	  	
      }	  
    		
      
    
    
    	
    	
    }

  2. #2
    Banned
    Join Date
    Aug 2017
    Posts
    861
    go and find that bubble sort in one of your post in here, ( i think it was yours) then reverse it and see what that does for you.

    here it is
    Arranging Random Numbers in Ascending Order

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
     
    
    int main(void)
    
    {
    
    int randNum;
    
    int myArray[100];
    
    int i;
    
    srand((int)time(0)); // Seeds Random Numbers
      
        for(i=99; i>0; i--)
    
      {
    
          randNum = rand()%20 + 1;
    
          printf("%d\n", randNum);
    
          myArray[i] = randNum;
             
      }   
    // missing return value;
    }
    Code:
     printf("%d\n", (myArray[i] = rand() % 20 + 1) );
    save typing and memory usage, and time.
    Last edited by userxbw; 10-16-2017 at 01:18 PM.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by userxbw View Post
    Code:
     printf("%d\n", (myArray[i] = rand() % 20 + 1) );
    save typing and memory usage, and time.
    He has more to do with the number than just print it, like store and sort it, so if anything this wastes time.

    Amusingly, I think the earlier assignment was the harder one. For this one, you can just print each element of the array after sorting.

  4. #4
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by whiteflags View Post
    He has more to do with the number than just print it, like store and sort it, so if anything this wastes time.

    Amusingly, I think the earlier assignment was the harder one. For this one, you can just print each element of the array after sorting.
    mmm run that
    Code:
    int main(void)
    
    {
    
    int randNum = 0;
    int myArray[100];
    int i;
    srand((int)time(0)); // Seeds Random Numbers
      
        for(i=101; i > 0; i--)
        {
    
        //  randNum = rand()%20 + 1;
    
          printf("%d\n", (myArray[i] = rand() % 20) );
          randNum++;
          printf("n %d\n", randNum);
    
         // myArray[i] = randNum;
             
      }   
      printf("\n hey\n");
      for (i = 0; i < 100; i++) // see if it has values in the array :)
         printf("%d\n", myArray[i]);
         
         
    return 0;
    }
    fix the numbers in the ( ) I was playing with it earlier

    I already completed this assignment in that link, if he needs to go the other way in sorting he just needs to reverse the bubble sort.

    looks like he has trained some of us? just do a minimal amount of code then toss it us to chew on. just saying.

    makes me wonder what his next semester will be like, how much will he really know when it comes time to apply the basics to greater things ahead?
    Last edited by userxbw; 10-16-2017 at 02:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arranging Random Numbers in Ascending Order
    By csmith03 in forum C Programming
    Replies: 9
    Last Post: 10-16-2017, 03:06 PM
  2. Flowchart - three numbers in increasing order
    By Dontknowtbh in forum C Programming
    Replies: 1
    Last Post: 09-02-2016, 12:22 PM
  3. Help with displaying random numbers
    By Bumps in forum C++ Programming
    Replies: 12
    Last Post: 10-03-2009, 12:29 PM
  4. Generating a sequence of numbers in a random order
    By mirbogat in forum C Programming
    Replies: 15
    Last Post: 08-12-2008, 02:01 PM
  5. List of numbers in random order
    By KneeGrow in forum C++ Programming
    Replies: 11
    Last Post: 02-08-2005, 03:25 AM

Tags for this Thread