LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   i found a way to random generate 4 unique numbrs but prob is sometimes it doesn't run (https://www.linuxquestions.org/questions/programming-9/i-found-a-way-to-random-generate-4-unique-numbrs-but-prob-is-sometimes-it-doesnt-run-475847/)

icylicious 08-21-2006 06:22 AM

i found a way to random generate 4 unique numbrs but prob is sometimes it doesn't run
 
i found a way to random generate 4 unique numbrs but prob is sometimes it doesn't run.. pls help me what are tne necessary changes i should do. here's the code i did:

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

void rep(int *, int*, int*,int*);

int main(void)
{
int i, n=4, a, b,c,d;

srand(time(NULL));
for (i=0; i < n; ++i) {

a= rand() % 10;
b= rand() % 10;
c= rand()%10;
d= rand()%10;
};
rep(&a,&b,&c,&d);
return 0;
}

void rep(int*a, int*b,int*c,int*d)
{
int tmp;
if (*a !=*b)
{tmp = *b;
*b = tmp;
{if(*a!=*c)
{if(*b!=*c)
{if(*a!=*d)
{if(*b!=*d)
{if(*c!=*d)
printf("%d %d %d %d\n",*a,*b,*c,*d);} } } } }
return;
}
else
main();

}

cupubboy 08-21-2006 06:35 AM

I think you already have a thread about this .. could have at least just bumped that

I think you should use code tags

I think you should explain what "sometimes it doesn't run" means

I think that's all .. cheers


All times are GMT -5. The time now is 03:00 AM.