+ 1

How to write c++ program to generate random number

Write a program which defines three functions 1. genRandNum() This will generate 5 random numbers in range 1-100 and store them in array and print array on console. 2. findMinNum() This will search smallest number in unsorted part of array. 3. swapValue() If left number is smallest number then no need to swap otherwise swap the smallest number with left most unsorted number using swapValue().

29th Nov 2018, 6:30 PM
Ahmad Ali
Ahmad Ali - avatar
8 ответов
+ 2
"std::unsigned(time)" --> srand((unsigned)time(NULL)); rand() % 2; // "This will generate a number from 0 to 2" --> 0 to 1
29th Nov 2018, 7:03 PM
Babak
Babak - avatar
+ 3
"can you please write all code here..?" We do, Ahmad. But we get motivated if we see your attempt, first. Have you tried to implement something?
29th Nov 2018, 7:06 PM
Babak
Babak - avatar
+ 3
"if you want i will show you" That would be great. Attach your code here for inspection.
29th Nov 2018, 7:26 PM
Babak
Babak - avatar
+ 2
None of them, here is one of them you can do: #include <iostream> #include <time.h> #include <cstdlib> int main(){ std::unsigned(time) std::cout << rand() % 2; } //This will generate a number from 0 to 2
29th Nov 2018, 6:37 PM
Potato Hacker
Potato Hacker - avatar
+ 1
plus also this is off-topic, make sure to read Guidelines https://www.sololearn.com/discuss/1316935/?ref=app before posting.
29th Nov 2018, 6:38 PM
Potato Hacker
Potato Hacker - avatar
0
can you please write all code here..?
29th Nov 2018, 7:04 PM
Ahmad Ali
Ahmad Ali - avatar
0
yes but failed every time
29th Nov 2018, 7:16 PM
Ahmad Ali
Ahmad Ali - avatar
0
if you want i will show you
29th Nov 2018, 7:17 PM
Ahmad Ali
Ahmad Ali - avatar