Excercise in C: Smallest Positive Number

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?

৪টি মন্তব্য:

  1. Output is 232792560
    --------------------------------

    #include
    #include
    int main()
    {
    int num=20,flag=0;

    while(flag==0)
    {
    if ((num%2)== 0 && (num%3) == 0 && (num%4) == 0 && (num%5) == 0 && (num%6) == 0
    && (num%7) == 0 && (num%8) == 0 && (num%9) == 0 && (num%10) == 0 && (num%11) == 0 && (num%12) ==0
    && (num%13) == 0 && (num%14) == 0 && (num%15) == 0 && (num%16) == 0 && (num%17) == 0 && (num%18)==0
    && (num%19) == 0 && (num%20) == 0)

    {
    flag=1;
    printf("%d",num);
    }

    num++;
    }
    return 0;
    }

    উত্তরমুছুন
  2. #include
    main()
    {
    int num=20,pl=0;

    while(pl==0)
    {
    if ((num%2)== 0 && (num%3) == 0 && (num%4) == 0 && (num%5) == 0 && (num%6) == 0
    && (num%7) == 0 && (num%8) == 0 && (num%9) == 0 && (num%10) == 0 && (num%11) == 0 && (num%12) ==0
    && (num%13) == 0 && (num%14) == 0 && (num%15) == 0 && (num%16) == 0 && (num%17) == 0 && (num%18)==0
    && (num%19) == 0 && (num%20) == 0)

    {
    pl=1;
    printf("%d",num);
    }

    num++;
    }
    return 0;
    }

    উত্তরমুছুন
  3. #include
    #include
    int main(int argc, char *argv[])
    {
    double nl_dbl_min = std::numeric_limits< double >::min();
    double nl_dbl_dmin = std::numeric_limits< double >::denorm_min();
    int *p = new int[2];
    *p = 0;
    *(p + 1) = 1;
    double *my_dbl_min = reinterpret_cast< double* >(p);
    std::cout << nl_dbl_min << '\t' << nl_dbl_dmin << '\t' << *my_dbl_min << std::endl;
    delete p;
    return 0
    }

    উত্তরমুছুন