Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C program that reads 2 positive integers from the user using scanf() function, prints the following information, and then terminates: - the average
Write a C program that reads 2 positive integers from the user using scanf() function, prints the following information, and then terminates:
- the average of the two (this should be printed as a floating point number.)
- whether each number is a prime number or not
In order to see if two numbers are relatively prime, you should calculate the GCD using Euclidean algorithm. You are allowed to look up the algorithm and/or code on the Internet, in which case you should cite the source in your README.txt file.
Your code should be organized as follows:
- gcd.h & gcd.c: GCD calculation function header and definition
- prime.h & prime.c: prime number testing function header and definition
- main.c: everything else
- Makefile
All files must be named EXACTLY as above, case-sensitive. When you run "make", it should build an executable file called "main".
The makefile should have correct dependencies. For example, if you build everything, change prime.h, and run make again, only prime.c and main.c should recompile, not gcd.c. (You can simulate changing a file by using touch command.)
You can use printf("You typed in %d and %d ", x, y);
to print integers, and printf("The average is: %f ", avg);
to print a floating point number. And you can use
scanf("%d", &x);
to read an integer that the user types in. Dont forget the ampersand in front of the variable.
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