0% found this document useful (0 votes)
42 views

OOP Assignment Part 2

The document describes a program that takes a positive integer input and checks if there are positive integers X and Y that satisfy the equation X^2 + Y^2 = Z^2. If a solution exists, the program outputs X and Y. If no solution exists, it outputs "No X and Y exist". It provides examples of integers where solutions both do and do not exist to demonstrate the two possible outcomes.

Uploaded by

Jessica Smith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

OOP Assignment Part 2

The document describes a program that takes a positive integer input and checks if there are positive integers X and Y that satisfy the equation X^2 + Y^2 = Z^2. If a solution exists, the program outputs X and Y. If no solution exists, it outputs "No X and Y exist". It provides examples of integers where solutions both do and do not exist to demonstrate the two possible outcomes.

Uploaded by

Jessica Smith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

7.

Write a program that can take an Input as positive integer (call it Z) and displays the positive integers X
and Y if the following Equation is satisfied by X and Y:
X^2 + Y^2 = Z^2
For example consider the positive integer Z = 5. There exist positive integers X = 3 and Y = 4 such that
5^2 = 3^2 + 4^2 = 9 + 16 = 25 (=5^2). So if the user inputs 5, your program must display 3 and 4.
However, there are many positive integers Z for which NO POSITIVE INTEGERS X AND Y EXISTS
THAT SATISFY THE ABOVE EQUATION. So for a given positive integer Z there are two possibilities.
One possibility is that there may exist two positive integers X and Y such that X^2 + Y^2 = Z^2. The
second possibility is that there may not exist any pair of positive integers X and Y satisfying the equation.
IF NO POSITIVE INTEGERS X AND Y EXIST SATISFYING THE EQUATION FOR A POSITIVE
INTEGER Z WHICH WAS INPUT TO YOUR PROGRAM, THEN YOUR PROGRAM MUST DISPLAY
THE MESSAGE NO X AND Y EXIST. OTHERWISE YOUR PROGRAM MUST DISPLAY THE
VALUES OF X AND Y SATISFYING THE EQUATION.
Another example of an integers Z, X, Y satisfying the equation is 15,9,12 because 15^2 = 9^2 + 12^2 = 81
+ 144 = 225 (=15^2). Examples of integers Z for which no such X and Y exist are Z=17, Z=38, Z=67 etc.

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int a=0, b=0, z = 0,num=0,x=0,y=0;
Console.Write("Enter the Number : ");
num =int.Parse(Console.ReadLine());
for (int row = 1; row < num; row++)
{
for (int col = 1; col < num; col++)
{
z = num*num;
a = row;
b = col;
x = row*row;
y = col*col ;
if (z==x+y)
{
row = num + 1;
col = num + 1;
}
}
}
if (x + y == z)
{
Console.WriteLine("\n\nThe Square of " + a + "\t= " + x + "\nThe Square
of " + b + "\t= " + y + "\nThe Square of " + num + "\t=" + z);

Console.WriteLine("\n" + x + " + " + y + "\t= " + z);


}
else
{
Console.WriteLine("No X and Y exist");
}
Console.ReadLine();
}
}
}

You might also like