Write a C program to generate n random numbers.
int main() {
int i, n, value;
/* get the no of random nos needed by user */
printf("Enter the value for n:");
scanf("%d", &n);
/* print n random numbers */
printf("First %d random numbers:\n", n);
for (i = 0; i < n; i++) {
value = rand();
printf(" %d\n", value);
}
return 0;
}
Output:
jp@jp-VirtualBox:~/cpgms/lab_pgms/02_control_flow$ ./a.out
Enter the value for n:10
First 10 random numbers :
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
1189641421
Enter the value for n:10
First 10 random numbers :
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
1189641421
No comments:
Post a Comment