Program is working with user inputs.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(){
    FILE *fp;// pointing FILE fp file 
    int number,a0,a1;//Defining to 3 integer 1th for numbers 2nd and 3th for range 
    fp=fopen("values.txt","w");//Opening file to write values
    srand(time(0));//This line makes that the rand function works properly.
    printf("how many numbers generated? ");//Want input from user
    scanf("%d",&number);//save the number in number variable
    printf("\nSpecify the range of numbers to generate\nWhich number start with?");//to get input from user
    scanf("%d",&a0);// save firstly which start
    printf("\nWhich number end with?");
    scanf("%d",&a1);// save secondly which end
    for(int i=0;i!=number;i++){
        fprintf(fp,"%d\n",(rand()%(a1-a0))+a0);
            //fprintf function working for print text to values.txt
            // rand function generate random number
    }
    return 0;
}

compile and run.

Leave a Reply

Your email address will not be published. Required fields are marked *