-
March 25th, 2017, 11:29 AM
#1
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)
-
March 25th, 2017, 11:34 AM
#2
Re: Find the next largest even multiple of the following...
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 25th, 2017, 12:56 PM
#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.
Victor Nijegorodov
-
March 25th, 2017, 01:11 PM
#4
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 25th, 2017, 01:40 PM
#5
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)
-
March 25th, 2017, 01:55 PM
#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
-
March 25th, 2017, 02:04 PM
#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!
Victor Nijegorodov
-
March 25th, 2017, 02:14 PM
#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++?
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++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|