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