Computer Science, asked by mnandhinidevi3427, 1 year ago

Write a function that receives two numbers and generates a random number from that range. Using this function, the main program should be able to print three numbers randomly.

Answers

Answered by hotelcalifornia
0

Answer:

The following program receives two number and generates a random number from it. Finally, it print outs three numbers in random.

Explanation:

#include <stdio.h>  

#include <stdlib.h>  

#include <time.h>  

void printRandomnumbers(int startrange, int endrange,  int count)  

{  

int i, num;  

for (i = 0; i < count; i++)

{  

 num = (rand() %  

 (endrange - startrange+ 1)) + startrange;  

 printf("%d ", num);  

}  

}  

void main()  

{  

int startrange , endrange, count = 3;  

 scanf(“%d”, startrange);

scanf(“%d”, endrange);

 srand(time(0));  

printRandomnumbers (startrange, endrange, count);  

return;  

}

Answered by prakharagrawal6055
0

Answer:

#definion of the program

def random(num1,num2):

   print("Random three numbers between",num1,"And",num2,"are:")

   for i in range(3):

       import random

       if n1>n2:

           print(random.randrange(num2,num1))

       else:

           print(random.randrange(num1,num2))

           

#main program

n1=int(input("Enter the first number:"))

n2=int(input("Enter the second number:"))

random(n1,n2)

Explanation:

Similar questions