Question
public class ImpPythTripEx public static double[][] triples = new double[3][3]; public static void inputTwoSides(double sideAIn, double sideBIn, int rowIndex) { triples[rowIndex][0] = sideAIn; triples[rowIndex][1] =
public class ImpPythTripEx
public static double[][] triples = new double[3][3];
public static void inputTwoSides(double sideAIn, double sideBIn, int rowIndex) { triples[rowIndex][0] = sideAIn;
triples[rowIndex][1] = sideBIn;
triples[rowIndex][2] = Math.sqrt(Math.pow(sideAIn, 2) + Math.pow(sideBIn, 2));
}
public static void inputOneSideAndHyp(double sideAIn, double hypIn, int rowIndex) { triples[rowIndex][0] = sideAIn;
triples[rowIndex][2] = hypIn;
triples[rowIndex][1] = Math.sqrt(Math.pow(hypIn,2) - Math.pow(sideAIn, 2));
}
public static void printTriple() {
for(int i=0; i<3; i++) {
System.out.print("PythTriple [ ");
for(int j=0; j<3; j++) {
if(j==0) {
System.out.print("sideA=");
}
if(j==1)
{ System.out.print("sideB=");
}
if(j==2)
{ System.out.print("hyp=");
}
System.out.print(String.format("%5.3f",triples[i][j]) + " ");
}
System.out.println("]"); } }
public static void main(String[] args) {
inputOneSideAndHyp(3,5,0);
inputOneSideAndHyp(1, Math.sqrt(2),1);
inputTwoSides(2, 3, 2);
printTriple();
}}
1.) Write a new version of the imperative programming exercise (involving Pythagorean Triples) in C, with alterations that include
using an array of instances of a Pythagorean Triple struct instead of a two dimensional array
make sure the array is on the heap. Be sure to use the malloc function
***Please include screenshots of both the input and output! Thank you :)***
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started