CS_201 Assignment no 1 Solution Fall 2017




















#include<iostream>
#include<stdlib.h>

using namespace std;
main()
{
 int upperlimit, lowerlimit, sum=0;
 cout<<"please enter lower limit (Greater > 0 ) = ";
  cin>>lowerlimit;
   if (lowerlimit>0)
 
{

   cout<<"please enter upper limit (Greater > lower limit) = ";
    cin>>upperlimit;
    if (upperlimit>lowerlimit)
 {
    for(int i=lowerlimit; i<=upperlimit; i++)
{
    if(i%4==0)
 {                 
   sum=sum-i;
}
else
{
 sum=sum+i;
}
  }
  cout<<"calculated number is = "<<sum<<endl;
}
else
{
cout<<"lower limit should be (greater > 0) ";

}
  system("pause");
}
}

Post a Comment

Previous Post Next Post