Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;

}

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

What is the role of the CPAB?

Answered: 1 week ago

Question

4. Label problematic uses of language and their remedies

Answered: 1 week ago