Thursday, January 19, 2012

smallest no divisble by numbers between 1 and 20

/*
 * bhatt.umang7@gmil.com
 */
/*
 * 2520 is the smallest number that can be divided
 * by each of the numbers from 1 to 10 without any remainder.
 * What is the smallest positive number that is evenly
 * divisible by all of the numbers from 1 to 20?
 */

#include<iostream>

using namespace std;

int main()

{

    long n1 = 20;

    long ans =1 ; 

    bool b = true ;

    int i = 0;

    while ( true )

    {

        b = true;

        for ( i = 1 ; i <= n1 ; i++ )

        {

            if (ans%i==0)

            {

            }

            else

            {

                b = false;

                break;

            }

        }

        if (b == true)

        {

            break;

        }

        ans++;

    }

    cout<< "Ans is "  <<  ans ;

    return 0;

}

No comments:

Post a Comment