Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:00:48+00:00 2026-06-14T14:00:48+00:00

Suppose you input A = 15, B = 6, The answer is 18. What

  • 0

Suppose you input A = 15, B = 6, The answer is 18. What algorithm do I need?

This is what I try, but it doesn’t work:

#include <stdio.h>

int main() {
int a, b;

scanf("%d %d", &a, &b);

for (  ; a % b != 0; a++ ) {
    if ( a % b == 0 ) {
        printf("%d\n", a);
        return a;
    }
}
return 0;
}

I get infinite loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:00:51+00:00Added an answer on June 14, 2026 at 2:00 pm

    The question (now) asks for:

    The next multiple of b that is not less than a?

    Using your notation of a and b, you can write it directly like this:

    int NextMultipleUp(int a, int b)
    {
        int r = a % b;
        if (r == 0)
            return a;
        else
            return a + b - r;
    }
    

    The question originally asked for

    The next multiple of a that is not greater than b

    And for that the answer is

    int NextMultipleDown(int a, int b)
    {
        return b - b % a;
    }
    

    This was the answer for which the original comments applied to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I've got code like #include <iostream> using namespace std; int main() { cout
pt=[2] pt[0]=raw_input() when i do this , and give an input suppose 1011 ,
Suppose I have a form like this: Name:<input type=text name=xxx id=name/> Type:<select> <option>xx</option> <option>xx</option>
I am wondering how this would work in MVC 2. Suppose I want to
I suppose this scratches a vast topic, but what is the best approach in
I suppose I have a straightforward question to answer. I have this piece of
okay, so this is suppose to be part of the full code, but the
Suppose my input is ( a , b and c to distinguish between equal
Suppose the jQuery object of the input is $input. How to make its value
Suppose that my Haskell function is given an input, which is supposed to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.