Mcs 041 Assignment Solution Cs201

Write a program that will

  1. Ask the user to enter lower limit and upper limit in the form of integer numbers.
  2. The program will then add / sum all those numbers between upper limit and lower limit (including the lower and upper limits) which are NOT multiple of 4.
  3. This process should continue for all the remaining integer numbers up until the upper limit is reached.
  4. The program will then show the aggregate sum of all numbers for the given range.

Make sure that lower limit entered by the user should be greater than zero. Also the upper limit value entered by the user should be greater than the lower limit value.

Example:

Lower limit is 1 and Upper limit is 8 then the program will subtract 4 and 8 as these are the multiples of 4. While add remaining integers in the range (1+2+3-4+5+6+7-8 = 12). So, 12 is the calculated number.

Sample output for correct input:


Sample output for the wrong input:

Sample output for the wrong input:

Solution:

#include<iostream>

usingnamespace std;

main()

{

       int upperlmt, lowerlmt, sum = 0, a;

       cout <<"Please Enter Lower Limit <Greater Then 0 >: ";

       cin >> lowerlmt;

       if (lowerlmt > 0)

       {

              cout <<"Please Enter Upper Limit <Greater Than Lower Limit>: ";

              cin >> upperlmt;

              if (upperlmt > lowerlmt)

              {

                     for (a = lowerlmt; a <= upperlmt; a++)

                     {

                           if (a % 4 == 0)

                           {

                                  sum = sum - a;

                           }

                           else

                           {

                                  sum = sum + a;

                           }

                     }

                     cout <<"Calculated Number is "<< sum << endl;

              }

              else

              {

                     cout <<"Upper Limit Must Be Greater Than Lower Limit"<< endl;

              }

       }

       else

       {

              cout <<"Lower Limit Should Be Greater Then Zero"<< endl;

       }

       system("pause");

}

Энсей Танкадо всучил вам Северную Дакоту, так как он знал, что вы начнете искать. Что бы ни содержалось в его посланиях, он хотел, чтобы вы их нашли, - это ложный след. - У тебя хорошее чутье, - парировал Стратмор, - но есть кое-что. Я ничего не нашел на Северную Дакоту, поэтому изменил направление поиска.

One thought on “Mcs 041 Assignment Solution Cs201

Leave a Reply

Your email address will not be published. Required fields are marked *