Answer to Question #272740 in C++ for Ujoo

Question #272740

Write a program that fills an integer array of 1000 random numbers


between 1-100


Next count the number 6 appears in the array and output this information to the console.


1
Expert's answer
2021-11-28T11:45:02-0500
#include <iostream>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
using namespace std;






int main(){
	 //integer array of 1000 random numbers
	int numbers[1000];
	/* initialize random seed: */
	srand (time(NULL));
	for(int i=0;i<1000;i++){
		 numbers[i] = rand() % 100 + 1;
	}
	//count the number 6 appears in the array and output this information to the console.
	int countSix=0;
	for(int i=0;i<1000;i++){
		if(numbers[i]==6){
			countSix++;	
		}
	}
	cout<<countSix<<" times the number 6 appears in the array." << endl<< endl;
	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
APPROVED BY CLIENTS