I want C++ program that asks the user to input an ordered pair of integers, each
ID: 3541664 • Letter: I
Question
I want C++ program that asks the user to input an ordered pair of integers,
each between 2 and 5000. Then, for each integer of the pair, it should display that integer's factors
(greater than 1) that are themselves squares, and also display whether or not that integer is square-free.
Finally, it should display whether this ordered pair of integers is SWEET, SOUR, SALTY, or BITTER.
regarding :
If both of the integers in the pair are square-free, then this pair is SWEET.
? If the first integer in the pair is square-free but the second one is not, then this pair is SOUR.
? If the second integer in the pair is square-free but the first one is not, then this pair is SALTY.
? If neither of the integers in the pair are square-fee, then this pair is BITTER.
Explanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,firstNumber, secondNumber, temp, count1 =0, count2 = 0;
cout<<"Enter the first number of the pair: " <<endl;
cin>>firstNumber;
cout<<"Enter the second number of the pair: "<<endl;
cin>>secondNumber;
cout << "Integer factors of "<<firstNumber <<" which are themselves squares are :"<<endl;
for(i=2;i<=firstNumber;i++)
{
if(firstNumber%i==0)
{
temp = sqrt(i);
if(temp*temp == i) {
cout<<i<<" ";
count1++;
}
}
}
if (count1 == 0){
cout << "None" << endl;
}
cout << endl;
cout << "Integer factors of "<< secondNumber << " which are themselves squares are :"<<endl;
for(i=2;i<=secondNumber;i++)
{
if(secondNumber%i==0)
{
temp = sqrt(i);
if(temp*temp == i) {
cout<<i<<" ";
count2++;
}
}
}
if (count2 == 0){
cout << "None" << endl;
}
if (count1 == 0 && count2 ==0){
cout << "this pair is SWEET."<<endl;
}
else if (count1 == 0 && count2 >0){
cout << "this pair is SOUR."<<endl;
}
else if (count1 >0 && count2 == 0){
cout << "this pair is SALTY."<<endl;
}
else if (count1 >0 && count2 >0){
cout << "this pair is BITTER."<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.