Friday, 16 November 2012

Average of Numbers divisible by 3 between 1 and 100


#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;
}

No comments:

Post a Comment