I am using a Dev C++ GCC complier on windows. I used this code for my random number generator which prints 10 random numbers comprised of 0s and 1s
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int i,n;
int arr[50];
//int z=0,o=0;
//time_t t;
printf("Enter the no of binary random nos you want");
scanf("%d",&n);
//initializes the random number generator
srand(time(NULL));
//print the random numbers
printf("The random numbers are: ");
for(i=0;i<n;i++);
{
arr[i]=rand()%2;
printf("%d",arr[i]);
}
return (0);
}
However, it prints only one random number at a time instead of 10. Any help in pointing out my mistake will be appreciated
Aucun commentaire:
Enregistrer un commentaire