Tuesday, 1 May 2018

CS 201 Assignment solution 2018

// 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

Featured Post

All Answers of Quiz regarding to this course on Fiverr "Online Freelancing Essentials: Be A Successful Fiverr Seller"

To Clear All quiz of mentioned Course you can have a look on or check questions answers as well. Course name:  Online Freelancing Essentials...

Popular Posts