Answer to Question #292864 in C++ for Rubie Ann

Question #292864

Write a program that uses the srand() and time() function to print on the screen a truly random number from 1 trough 20 generated by the rand() function.

1
Expert's answer
2022-02-01T11:59:58-0500
#include <iostream>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
using namespace std;


int main(){


	srand (time(NULL));


	for(int i=0;i<13;i++){
		int number= rand() % 20 + 1;
		cout<<number<<"\n";
	}




	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog