Searching...

Average of Numbers divisible by 3 between 1 and 100

15:36

#include <iostream>
using namespace std;
int main()
{
double avg,sum=0,counter=0;
for(int j=1;j<=100;j++)
{
if(j%3==0)
{
counter++;
sum=sum+j;
}
}
avg=sum/counter;
cout << "The Average is = "<<avg<<endl;
return 0;
}

0 comments:

Post a Comment

Thanks For Your FeedBack....