Thursday, 3 May 2018

Cs201 Assignment 1 Solution 2018 Due Date 7 May 2018


 Cs201 Assignment No 1 Solution:


#include <iostream>

main()
{
int Limit;
int divisible = 0,
non_divisible = 0,
sum=0;

cout<<"enter number (1o to 150) : ";
cin>>Limit;

if (Limit <10)
    {
cout<<"\nenter value greater than 9"<<endl;
    }
else if (Limit >150)
    {
cout<<"\nenter value smaller than 150"<<endl;
    }


for (int x=1; x<=Limit; x++)
    {
if ((x%3 == 0) && (x%5 == 0))                       // if divisible by  both 3 and 5
            {
continue;   // go to the next repetition
            }

if ((x%3 == 0) || (x%5 == 0))               // if divisible by any one
        {
divisible ++;                 // increment the counter by 1
sum += x;                     // also add  it to the sum
        }

else
        {
non_divisible ++;   // if not divisible increment by 1
        }

    }

// displaying results

cout<<"\nTotal Number of Divisible values : "<<divisible<<endl;
cout<<"sum of values divisible by 3 or 5 : "<<sum;
    cout<<"\nTotal Number of Non Divisible values : "<<non_divisible<<endl;


No comments:

Post a Comment