How do you input random amount of numbers in C++?
Not difficult at all! use vector to store inputs, and use loop for input
#include <iostream> int main(void) { int random_number; std::cin >> random number; return 1; }
#include<stdlib.h > # include<iostream.h> void main() {randomise(); int n,a[1000];//n=no between no. of input will be; cin>>n; n=random(n); for(int i=0;i<n;i++) cin>>a[i]; }
this is not a correct method. Why should user supply total no. of inputs?? This forces him to count, and thus increases human work!! Avoid it! Software is considered to reduce human effort, not to increase unnecessarily.
Make use of the \(\text{ctime}\) library, initialize the random seed by writing \(\text{srand((unsigned int)time(NULL))}\) and obtain any random number you wish by calling the function \(\text{rand()}\). Of course, you may want to play around with the range of the function by making use of the \(\text{%}\) operator.
Join our real-time social learning platform and learn together with your friends!