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

void main()

{
	int i[100];
	int j[100];
	int k;
	int m;
	clrscr();
	printf("Enter the number of questions needed:");
	scanf("%d",&m);
	if (m<=100);
	{

		i[100]=rand()%m;
		printf("%d \n",i,rand());

		j[100]=rand()%m;
		printf("%d",j,rand());

		i[100]=rand()%m;
		printf("%d \n",i,rand());

		j[100]=rand()%m;
		printf("%d",j,rand());
	}


	getch();
}

I want to generate random numbers when I press the amount. i.e. If i enter 50, then it should generate 50 random numbers between 1-100. But when i do so, I get only two number for each integer. i comes 212 and j comes as 412, then the program terminates.

Can someone tell me, what i should do? Is there any problem in my rand statement? Or do i have to use any other statement or string?

Lots of problems in this code...

#include<stdio.h>
#include<conio.h>      // unnecessary, non-standard -- should not be used
#include<stdlib.h>
#include<string.h>
#include<time.h>

void main()           // MAIN is not and never has been a 'void' -- see below

{
	int i[100];   // create an array from i[0] to i[99]
	int j[100];
	int k;
	int m;
	clrscr();     // unnecessary, non-standard -- should not be used
	printf("Enter the number of questions needed:");
	scanf("%d",&m);
	if (m<=100);
	{

		i[100]=rand()%m;      // I only goes to 99 -- 100 is not part of the array
		printf("%d \n",i,rand()); // calculate and print a new random number. Among other problems.

		j[100]=rand()%m;      // see 'I' above
		printf("%d",j,rand());

		i[100]=rand()%m;      // You are replacing the value above
		printf("%d \n",i,rand());

		j[100]=rand()%m;      // same
		printf("%d",j,rand());
	}


	getch();  // non-standard -- should not be used.  GETCHAR() is made for this
}

void main() -- See this

I want to generate random numbers when I press the amount. i.e. If i enter 50, then it should generate 50 random numbers between 1-100.

How can you generate 50 values without a loop? You only generate 2 values for each array, and don't even store them in the arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.