Question
A Pythagorean triple consists of three integers that can be the side lengths of a right triangle. In that file will be two lines, each
A Pythagorean triple consists of three integers that can be the side lengths of a right triangle.
In that file will be two lines, each containing an integer: 5 3 If these two integers can be two members of a Pythagorean triple, you should print out the third integer: 4
If these two integers cannot form a Pythagorean triple, you should print -1.
In the tests/ directory you have 7 given input test cases.
In the answers/ directory you have the corresponding expected answers. You will receive 1 point for passing each predetermined test case.
Heres the code:
#include
#include
#include
int main(int argc, char* argv[]) {
// Open the filename given as the first command line argument for reading
FILE* fp = fopen(argv[1], "r");
if (!fp) {
perror("fopen failed");
return EXIT_FAILURE;
}
char buf[256];
char* string = fgets(buf, 256, fp);
int x = atoi(string);
// Printing in C.
// %d is the format specifier for integer numbers.
// is the newline character
printf( "%d ", x );
return EXIT_SUCCESS;
}
test0test1test2test3test4test5test6test7 answer0 answer 1 answer2 answer 3 answer4 answer5 answer6 answer 7 13 answer0.txtanswer1.txtanswer2.txtanswer3.txtanswer4.txtanswer5.txtanswer6.txtanswer7.txt 1254test1.txttest2.txttest3.txttest4.txttest5.txttest6.txttest7.txttest0.txtStep 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