Write a C++ PROGRAM to calculate Second number is multiple of first number or not (logic explained step by step)
Here is the C++ code to calculate Second number is multiple of first number or not .It takes input for first and second number and shows the result . You all should have in mind how it works exactly. Here is the algorithm.
Steps
User side
1: User asked to enter first number
2: User asked to enter second number
3: Screen shows the result
4: User asked to press 'c' to continue
5: If he/she does so, program again prompt for inputs other wise program ends.
Developer side
1: Declare variables that are going to be used in program .
2: Start a do while loop until user presses other than 'c'
3: Input first number from user
4: Input second number from user.
5: Pass both values to a function named 'multiple(int,int)' and store the returned value to a Boolean variable 'a'.
6: In the function check if the modulus of numbers equal to zero then return a true other wise return a false .
7: Now in the main function check if the value of variable 'a' is equal to true. If it is, then second is multiple of first number other wise second number is not multiple of first number.
8: Take input from user to continue or exist the program.
9: Outside the loop print a message for your confirmation.
10: Program ends here.
Code:
#include<iostream>
using namespace std;
bool
multiple(int, int);
void
main()
{ bool a;
int x, y,
fir, sec;
char c;
do
{
cout << "Enter first number=";
cin >> x;
cout << "Enter second value=";
cin >> y;
fir = x;
sec = y;
a=multiple(fir, sec);
if(a==true)
{cout<<"Second is multiple of first"<<endl;}
else
{cout<<"Second is not multiple of
first"<<endl;}
cout << "Enter \'c\' to cotinue= ";
cin >> c;
} while
(c == 'c');
cout<<"Program
is end here"<<endl;
system("pause");
}
bool
multiple(int first, int
second)
{
if
(second%first == 0)
{
return
true;
}
else
{
return
false;
}
}
Comments
Post a Comment