209k views
1 vote
Write a program to determine all pairs of positive integers, (a, b), such that a < b < n and (a 2 b 2 1)/(ab) is an integer. Here n is an integer and n > 1. Note: Your method should take n as a parameter and return nothing. You should print inside the method.c

User Soenke
by
4.7k points

1 Answer

5 votes

Answer:

following are the code to this question:

#include <iostream> //defining header file

using namespace std;

void me(int n) //defining a method me, that accept an integer value

{

int a,b,t1,t2; //defining integer variable

for(a = 1; a<n; a++) //defining loop to calculates a variable value

{

for(b=a+1; b<n; b++) //defining loop to calculates a variable value

{

t1=(a*a)+(b*b)+1; //hold value in t1 value

t2=a*b; // calculates multiplication value and hold in t2 variable

if(t1%t2==0) //defining condition that check calculated value is equal to 0

{

cout<<"("<<a<<","<<b<<")"; //print a and b value.

}

}

}

}

int main() //defining main method

{

int n; // defining integer variable

cout<< "Enter a number: "; //print message

cin>> n; // input value

if(n>1) //defining condition that check value is greater then 1

{

me(n); //call method and pass the value

}

else

{

cout<<"Enter a number, which is greater then 1"; //print message

}

return 0;

}

Output:

Enter a number: 3

(1,2)

Step-by-step explanation:

In the given C++ language code, a method "me" is defined, that accepts an integer value "n" as its parameter and this method does not return any value because its return type is void, inside the method two for loop is declared, that calculates a and b value and hold in t1 and t2 variable.

  • In the next step, if the condition is used, that checks module of t1 and t2 is equal to 0, then it will print a, b value.
  • Inside the main method an integer variable n is declared, that accepts a value from the user end, and use if block that checks user input is greater then 1, then we call method otherwise, print a message.
User Derek Reynolds
by
5.1k points