English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How I can Write a program In C++ that uses a function multiple(int,int) that determines for 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. What is the source code of this in C++?

2007-02-03 17:45:29 · 3 answers · asked by Ahsan Z 1 in Computers & Internet Programming & Design

3 answers

Code you asked for: -

#include
#include

int multiple(int,int);

void main()
{

clrscr();

int x,y,z;

cout<<"Enter a number"< cin>>x;

cout<<"Another number"< cin>>y;

z=multiple(x,y);

cout<
getch();
}

int multiple(int a,int b)
{

if(b%a==0)
return 1;
else
return 0;

}

2007-02-07 14:46:41 · answer #1 · answered by Santosh 2 · 0 0

Modulus arithmetic ! That's the "%" function.

If ( (big % little) == 0 ) then return 1;
// its a multiple

else return 0;
// it isn't

2007-02-03 17:50:34 · answer #2 · answered by Alan 6 · 0 0

check out http://www.pscode.com for great sample codes.

2007-02-03 18:05:58 · answer #3 · answered by Richard H 7 · 0 0

fedest.com, questions and answers