All pastes #534270 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-03 18:47 UTC
rendered paste body
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

//déclaration des fonctions utilisées
int prompt ();
int generator (int numbers);
int output();
int maxi();

//programme principal
int main ()
{
	generator(prompt());
	output();

getch();
return 0;
}

//programme demande
int prompt ()
{
	int number;
	
	printf("How many numbers to generate ?\n");
	scanf_s("%d",&number);
	
return number;
}

//programme générateur
int generator (int numbers)
{
	int min = 1, max = 1000;
	int generatedString[5000] = {0};
	int i;
	
	max=maxi()+1;
	srand(time(NULL));
	
	generatedString[0] = numbers;
	FILE* value = fopen("value.txt","w");
	if (value != NULL)
	{
		fprintf(value,"%d	% ",numbers);
		for (i = 1 ; i <= numbers ; i++)
		{
				generatedString[i] =  (rand() % (max+1 - min)+1);
				fprintf(value,"%d%	",generatedString[i]);			
		}
		fclose(value);
	}
	else
	{
		printf("\nError with the file.\n");
	};
return 0;
}

// programme pour choisir la valeur maximum des nombres.
int maxi ()
{
	int max;
	printf("What is the maximum value ?\n");
	scanf_s("%d", &max);
	printf("Generating numbers, please wait...\n");
	
return max;
}

//programme sortie
int output ()
{
	printf("\n\nFile successfully generated.\n\n");
	printf("Press any key to continue...");
	getch();
	
return 0;
}