Ask Question
20 April, 17:58

Write a program to determine all pairs of positive integers, (a, b), such that a < b 1. Note: Your method should take n as a parameter and return nothing. You should print inside the method. c

+4
Answers (1)
  1. 20 April, 19:40
    0
    following are the code to this question:

    #include / /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
    {

    for (b=a+1; b
    {

    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<<" ("<
    }

    }

    }

    }

    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)

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to determine all pairs of positive integers, (a, b), such that a < b 1. Note: Your method should take n as a parameter and ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers