- 1
please how do i write a code for this problem? Write a program to find the next largest even multiple for the following values of i and j:
2 Réponses
0
if I understand your question this code will work (sorry but I'm not English) (Just copy the code and paste it in the "code playground", then run. Read the comments, and if u need explainations just tell me ;-) ):
#include <iostream>
using namespace std;
int func (int, int);
//if you run this code on a PC then add the comments im main function to the code.
int main()
{
int j,i;
// cout<<"j=";
cin >> j;
// cout<<"/ni";
cin >> i;
// cout<<"/n/n"
cout << "next multiple: ";
cout<<func(j,i);
return 0;
}
int func (int x, int y)
{
int k=0;
do
{
k++;
} while (k%x != 0 || k%y != 0);
return k;
}
0
I have just realised what "even" means... sorry. So I changed the code (now, for example, if j=3 and i=5 then the output will be 30, and not 15):
#include <iostream>
using namespace std;
int func (int, int);
//if you run this code on a PC then add the comments im main function to the code.
int main()
{
int j,i;
// cout<<"j=";
cin >> j;
// cout<<"/ni=";
cin >> i;
// cout<<"/n/n"
cout << "next multiple: ";
cout<<func(j,i);
return 0;
}
int func (int x, int y)
{
int k=0;
do
{
k+=2;
} while (k%x != 0 || k%y != 0);
return k;
}