// created by Muhammad Hamza Baig
// search and find solution on my blog biggnerstart.blogspot.com
#include<iostream>
using namespace std;
int main()
{
int limit, sum=0, count=0; // Define veriable for futher usage
cout<<"Enter the limit in the range <10 ... 150>: ";
cin>>limit;
if (limit>=10) //applying condition
{
if(limit<=150) //applying condition
{
cout<<"Numbers which are divisible by both 3 and 5 is: ";
for(int i=1; i<=limit; i++)
{
if(i%3==0 && i%5==0) //applying condition
{
cout<<i<<" ";
}
}
for(int i=1; i<=limit; i++)
{
if((i%3==0 || i%5==0) && !(i%3==0 && i%5==0)) //applying condition
{
sum =sum + i;
}
}
cout<<"\nCalculated sum: "<<sum;
for(int i=1; i<=limit; i++)
{
if(i%3!=0 && i%5!=0)
{
count++;
}
}
cout<<"\nTotal Numbers which are not divisible by either 3 or 5 is: "<<count<<endl;
}
else
{
cout<<"Wrong input!! Limit shoud not be greater than 150"<<endl;
}
}
else
{
cout<<"Wrong input!! Limit shoud not be less than 10"<<endl;
}
system("pause");
}
No comments:
Post a Comment