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++?
How I can Write a program In C++ that uses a function multiple(int,int) that determines for a pair of integers
Code you asked for: -
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
int multiple(int,int);
void main()
{
clrscr();
int x,y,z;
cout%26lt;%26lt;"Enter a number"%26lt;%26lt;endl;
cin%26gt;%26gt;x;
cout%26lt;%26lt;"Another number"%26lt;%26lt;endl;
cin%26gt;%26gt;y;
z=multiple(x,y);
cout%26lt;%26lt;z%26lt;%26lt;endl;
getch();
}
int multiple(int a,int b)
{
if(b%a==0)
return 1;
else
return 0;
}
Reply:Modulus arithmetic ! That's the "%" function.
If ( (big % little) == 0 ) then return 1;
// its a multiple
else return 0;
// it isn't
Reply:check out http://www.pscode.com for great sample codes.
free survey
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment