CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

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

1. Junior Member
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. ## Re: Find the next largest even multiple of the following...

and the c++ question is?

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

Originally Posted by jamsdolpw
...
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.

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

[Thread moved from Visual c++ forum as not using Visual c++]

5. Junior Member
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. Junior Member
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 02:05 PM. Reason: added Code tags

7. ## 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!

8. ## 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++?

#### Posting Permissions

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

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)