Write a program that reads in two integers and determines and prints if the first is a
multiple of the second.
a) first the program using if statements
b) then the program using if/else statements
//***************** first.cpp *********************************
//first programm
#include <iostream>
using namespace std;
int main() {
int a;//first number
int b;//secon number
cout<<"Please input first number: ";
cin>>a;
cout<<"Please input the second number: ";
cin>>b;
if(a%b==0)
cout<<a<<" "<<b<<endl;
return 0;
}
//***********************************************************
//************************** second.cpp **********************
//second programm if/else
#include <iostream>
using namespace std;
int main() {
int a;//first number
int b;//secon number
cout<<"Please input first number: ";
cin>>a;
cout<<"Please input the second number: ";
cin>>b;
if(a%b==0)
cout<<a<<" "<<b<<endl;
else
cout<<"Sorry the first isn't multiple of the second\n";
return 0;
}
//**********************************************************
Comments
Leave a comment