Search This Blog

Saturday, 5 May 2018

Solution of CS201 Assignment 1 2018


#include<iostream>
using namespace std;

int main()
{
int limit, sum=0, count=0;

cout<<"Enter the limit in the range <10 ... 150>: ";
cin>>limit;
if (limit>=10)
{
if(limit<=150)
{
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)
{
cout<<i<<", ";
}
}
for(int i=1; i<=limit; i++)
{
if((i%3==0 || i%5==0) && !(i%3==0 && i%5==0))
{
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;
}
else
{
cout<<"Wrong input!! Limit shoud not be greater than 150"<<endl;
}
}
else
{
cout<<"Wrong input!! Limit shoud not be greater than 10"<<endl;
}
return 0;
}

    

No comments:

Post a Comment