1. How to generate random number in C++, write a simple C++ program that will generate random number from 1 to 100?
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n;
cout << "How many random number do yoi want? ";
cin >> n;
for (int i=0; i<n; i++) {
int q = rand() % 100 + 1;
cout << q << endl;
}
}
Comments
Leave a comment