Like Tree2Likes
  • 2 Post By bernt

Help with the Programme (ARRAYS)

This is a discussion on Help with the Programme (ARRAYS) within the C Programming forums, part of the General Programming Boards category; HELP PLEASE TO RESOLVE THE EXERCISE Code: /* Description: Extract Casual 100 Numbers .... but make a programme in which ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    9

    Help with the Programme (ARRAYS)

    HELP PLEASE TO RESOLVE THE EXERCISE

    Code:
    /*
      Description: Extract Casual 100 Numbers .... but make a programme in which an already extracted Numer W'ont repeat.
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <time.h>
    
    int main (){
             
             int N=100;
             int num[N];
             int i;
        
        
             //inizio algortimo
        
             srand((unsigned)time(NULL));
             num[0]=1;
             num[99]=100;
             
        
        for(i=0;i<N;i++){
                            
             num[N]=rand()%(num[99]-num[0]+1)+num[0];    /*Formula for extracting Casual(random) Numbers with the biggest and smalletst value included */ 
    
             printf("\n%d : %d",i,num[N]);
             N++;
        }
             
        
             printf("\n\n\n");
             //system("pause");
             getch();
    }

    im trying first to extract 100 random (Casual ) numbers .... extracted by PC ... but after extracted 7 numbers the programme .. gives me the error ... like in this picture -->
    Name:  Immagine 1.jpg
Views: 106
Size:  37.5 KB


    please help me to solve this problem .... and at last tell me how to do that the same number wont repeat in the extracted numbers ...

    This is my first exercize with the Arrays ... and im not able to do it .. plz help

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    For a non repeating random numbers google "Fisher-Yates shuffle".

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Code:
             num[N]=rand()%(num[99]-num[0]+1)+num[0];    /*Formula for extracting Casual(random) Numbers with the biggest and smalletst value included */
     
             printf("\n%d : %d",i,num[N]);
    Did you mean to use 'i' here instead of N?
    Consider this post signed

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    9

    No repeating ??

    Quote Originally Posted by bernt View Post
    Code:
             num[N]=rand()%(num[99]-num[0]+1)+num[0];    /*Formula for extracting Casual(random) Numbers with the biggest and smalletst value included */
     
             printf("\n%d : %d",i,num[N]);
    Did you mean to use 'i' here instead of N?


    i have tried to remove N++;

    and now it shows me 1<=Numbers<=100 ..... casual Numbers
    but now what do i have to do for dont make it repeat the already extracted numbers ???
    my actual programme is
    Code:
    int main (){
             
             int N=100;
             int num[N];
             int i;
        
        
             //inizio algortimo
        
             srand((unsigned)time(NULL));
             num[0]=1;
             num[99]=100;
             
        
        for(i=0;i<N;i++){
                            
             num[N]=rand()%(num[99]-num[0]+1)+num[0];
             printf("\n%d : %d",i,num[N]);
             _sleep(100);
        }
             
        
             printf("\n\n\n");
             //system("pause");
             getch();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c programme
    By yousra fatima in forum C Programming
    Replies: 1
    Last Post: 11-13-2011, 03:32 AM
  2. about this programme
    By kasun007 in forum C Programming
    Replies: 1
    Last Post: 03-07-2011, 08:52 PM
  3. programme
    By muraja in forum C++ Programming
    Replies: 1
    Last Post: 04-14-2010, 01:44 PM
  4. help me with this programme
    By ChrisWang in forum C++ Programming
    Replies: 1
    Last Post: 07-01-2008, 03:21 AM
  5. Is this programme do-able....by me!
    By maradoo in forum C Programming
    Replies: 4
    Last Post: 06-05-2002, 10:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21