How to generate limited number in c

Asked

Viewed 21 times

1

I’m looking for a way to make some random numbers, and I have this code for now. I wanted to make random numbers of 26 to 100, and I’m not getting it... How could I do that?

NOTE: I’m a newbie, and I’m doing a TCC job

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h> //para usar o rand e time

//programa principal
void main()
{
    //o programa vai aqui!!!
    int numeros[6], gerado, cont, aux;
    //acertar a semente geradora
    srand(time(NULL));

    cont = 0;
    while(cont < 6)  
    {
        //gera  numeros randomicos entre 1 e 60
        gerado = 1 + (rand() % 60);

        //procurar se existe o numero ja gerado
        for(aux=0; aux < cont; aux++)
        {
            if(gerado == numeros[cont]) 
                break; //encerra o for()    
        }
        //verifica se achou
        if(aux < cont)
            continue; //volta direto para o while
        //se nao, armazena o numero gerado no vetor 

        //armazena o numero gerado no vetor
        numeros[cont] = gerado;
        //avança
        cont++;
    }

    //exibir os numeros
    for(cont=0; cont<1; cont++) 
    {
        printf("%d ", numeros[cont]);
    }
}

Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.