Find the next largest even multiple of the following...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Find the next largest even multiple of the following...

  1. #1
    Join Date
    Mar 2017
    Posts
    6

    Find the next largest even multiple of the following...

    To round off an integer m to the next largest even multiple of another integer n the following
    formula can be used: k = m + n m % n
    Write a program to find the next largest even multiple for the following values of m and n:
    (m ,n)=(365,7) , (m ,n)=(12258,23) and (m , n)=(996 ,4)

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,873

    Re: Find the next largest even multiple of the following...

    and the c++ question is?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,010

    Re: Find the next largest even multiple of the following...

    Quote Originally Posted by jamsdolpw View Post
    ...
    Write a program to find the next largest even multiple for the following values of m and n:
    ...
    Please, read carefully the Announcement: Before you post...., and particularly the A special note about Homework section.
    Victor Nijegorodov

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,873

    Re: Find the next largest even multiple of the following...

    [Thread moved from Visual c++ forum as not using Visual c++]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  5. #5
    Join Date
    Mar 2017
    Posts
    6

    How to find the next largest even multiple?

    Write a program to find the next largest even multiple for the following values of m and n:
    (m ,n)=(365,7) , (m ,n)=(12258,23) and (m , n)=(996 ,4)

  6. #6
    Join Date
    Mar 2017
    Posts
    6

    Re: How to find the next largest even multiple?

    Code:
    #include <stdio.h>
    
    int main (void)
    {
        int i;
        int j;
        int nextmultiple;
    
        nextmultiple = (i + j) - (i % j);
    
        i = 365;
        j = 7;
    
        printf ("The next largest even multiple when i = 365 and j = 7 is %i\n", nextmultiple);
    
        i = 12258;
        j = 23;
    
        printf ("The next largest even multiple when i = 12,258 and j = 23 %i\n", nextmultiple);
    
        i = 996;
        j = 4;
    
        printf ("The next largest even multiple when i = 996 and j = 4 %i\n", nextmultiple);
    
        return 0;
    }
    Last edited by VictorN; March 25th, 2017 at 03:05 PM. Reason: added Code tags

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,010

    Re: Find the next largest even multiple of the following...

    [merged threads...]
    Dear jamsdolpw, please, don't start new threads with the same problem as you have already started!
    And, please, always use Code tags while posting code snippets!
    Victor Nijegorodov

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,873

    Re: Find the next largest even multiple of the following...

    Code:
    nextmultiple = (i + j) - (i % j);
    This is trying to calculate nextmultiple before the values of i and j have been set. This calculation needs to be done after the required values of i and j have been assigned.

    PS Are you learning c or c++?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)