OOP Assignment Part 2
OOP Assignment Part 2
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);