Write a program that has a function multiple
that determines a pair of integers whether the second
integer is a multiple of the first.The function should
take two integer arguments and return 1(true) if the
second is a multiple of the first, and 0(false) otherwise.
Use this function in a program that inputs a series of pairs of integers ?

use a call function

OK, so we now know what the program you're working on is supposed to do. What problem are you having with it? Do you know how to write the function, and how to use it once it is written? Are you stuck on some part of it?

You must understand, we will not write this program for you. We are here to help you learn, not to help you cheat. While that may not be your intention, just dumping the problem statement on us comes across as a demand to do your work for you, and that is simply not going to happen.

Edited 4 Years Ago by Schol-R-LEA

What have you done so far to complete the task aside from starting this thread in the hopes that someone will give you the answer?

I'll get you started with a function skeleton - show what code you come up with if you have problems.

int multiple(int first, int second)
{
    // fill in the blanks
    // how do you determine whether first divided by second gives a remainder of zero?
}

for this you will could use a few methods. try reading about the following
- function prototypes and implementation
- math operands in c++( ill help you with this one) Click Here
- and the difference between INT / DOUBLE / etc

once done think of a nice way to handle the problem

#include <stdio.h>
#include<math.h>
//function declartion
int multiple(int x,int y);

int main()
{
    int k,x,y,z,temp;
    printf("\nEnter the First integer");
    scanf("%d",&x);
    printf("\nEnter the Secound integer");
    scanf("%d",&y);

    if (y>x)
    {   temp=y;
        y=x;
        x=temp;
    }

    //function call
    k = multiple(x,y);
    if (k==1)
    { printf("\n%d is a multiple of %d\n",x,y);}
    else
    { printf("\n%d is not a multipule of %d\n",x,y);
    return (0);
}

int
multiple(int x,int y)
{
    z= x % y;
    if ( z == 0 )
    {return(1);
    }
    else 
    {   return(0);}
}

that's what i have done so far but it's wrong and i cant find where i had mistaken ?

What sort of problem is occurring? Is it not compiling (it shouldn't, as I'll expain below)? Is it compiling but crashing? Is it giving the wrong results? Can you explain the problem that is occurring?

I do see at least one show-stopper, in that you aren't declaring the variable z in the function multiple(). That by itself should prevent the program from compiling.

Also, I think you'll find that you want to reverse the modulo operation; as it is now, it would return 1 if x is a multiple of y, rather than the other way around.

BTW, is this program supposed to be in C++, or in C? I ask this because the code is C code (modulo the C++-style comments), and while it should compile under C++ as well, it does not take advantage of any of the C++ methods, and uses the older C-style headers.

As a final bit, you could simplify this function by a bit of a trick:

int multiple(int x, int y)
{
    return !(y % x);   // returns 1 if zero, 0 otherwise
}

This works because, in C and C++, any integer value other than 0 is treated as true.

Edited 4 Years Ago by Schol-R-LEA

hello, im not really good at c++ but here's what i think is wrong

int
multiple(int x,int y)
{
z= x % y;
if ( z == 0 )
{return(1);
}
else
{ return(0);}
}

variable "z" , u defined it inside int main's scope... i think u should define it inside int multiple's scope
please correct me if im wrong

This article has been dead for over six months. Start a new discussion instead.