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.
#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;
}
Comments
Leave a comment