Skip to content

Instantly share code, notes, and snippets.

@trashvin
Last active November 1, 2021 09:35
Show Gist options
  • Save trashvin/d12e1885ec8eec7acba9da6d8d66a3be to your computer and use it in GitHub Desktop.
Save trashvin/d12e1885ec8eec7acba9da6d8d66a3be to your computer and use it in GitHub Desktop.

Revisions

  1. trashvin renamed this gist Nov 1, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. trashvin renamed this gist Nov 1, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. trashvin created this gist Nov 1, 2021.
    35 changes: 35 additions & 0 deletions cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #include <iostream>
    #include <math.h>
    using namespace std;

    bool isDivisible(double number, double divisor);

    int main()
    {
    // generate 20 random numbers and checkif div by 10
    for (int i = 0; i < 20; i++)
    {
    double number = rand() % 1000;

    if (isDivisible(number, 10))
    {
    cout << "the number " << number << " is divisible by 10" << endl;
    }
    else
    {
    cout << "the number " << number << " is NOT divisible by 10" << endl;
    }
    }
    return 0;
    }

    bool isDivisible(double number, double divisor)
    {
    double floatPart, integerPart = 0;
    double quotient = number / divisor;

    if (modf(quotient, &integerPart) == 0)
    return true;
    else
    return false;
    }