Answer to Question #211400 in C++ for Telo

Question #211400

Write C++ program to generate 10 random numbers in the interval [ 20, 100], and find the mean of the

numbers that are divisible by 3 or 5


1
Expert's answer
2021-06-28T07:24:34-0400
#include <iostream>
#include <cstdlib>


using namespace std;


int main(){
	int i, randomnumber, number;
	//int arr=[] ;
	float sum=0 ;
	float mean;
	for (i=0; i<10 ; i++){
	// generating random numbers
		randomnumber = ((rand() % (100 + 1 - 20)) + 20 );
		if (randomnumber % 3 == 0 || randomnumber % 5 == 0  ){
			// getting number of numbers which are divisible by 3 or 5
			number += 1;
			// finding sum of these values/numbers
			sum += randomnumber;
			
		}
		
	}
	// getting mean of the numbers
	mean = sum / number;
	cout << mean << endl;
	
	
}

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