Question: Project 1, IT Program Design Create a program that prompts for a positive number greater than 2 (check this condition), then keeps taking the square
Project 1, IT Program Design
Create a program that prompts for a positive number greater than 2 (check this condition), then keeps
taking the square root of this number until the square root is less than 2. Print the value each time the
square root is taken, along with the number of t
imes the operation has been completed.
Print the values
to 3 decimal places as shown in the example output.
Use t
he sqrt function in math.h
.
double sqrt(double x)
The function
returns the square root of
x.
1. Name your program square_root.c
2. T
o check
the condition that the number entered by the user is greater than 2, you will need a loop.
3. Format the output to print the values to only 3 decimal places as shown.
4. Compile the program with option
-
lm to include the math library:
gcc
-
lm
-
Wall
square
_root.c
A sample input/output:
Enter an integer greater than 2
:
0
Output:
Invalid input, please enter again,
Enter an integer greater than 2:
-
4
Invalid input, please enter again,
Enter an integer greater than 2: 1
Invalid input, please enter again,
Enter an integer greater than 2: 20
1: 4.472
2: 2.115
3: 1.454
Before you submit:
1.
Compile with
Wall
.
Wall shows the warnings by the compiler.
Be sure it compiles on
student
cluster
with no errors and no warnings.
gcc
-
lm
-
Wall
square_root
.c
2.
Be sure your Unix source file is read & write protected.
Change Unix f
ile permission on U
nix:
chmod 600 square_root
.c
3.
Test your program with the shell script
try_
sqrt
on Unix:
chmod
+x try_sqrt
./try_sqrt
4.
Submit
square_root
.c
on Canvas>Assignments
>
Project 1
.
Grading
Total points: 100
1.
A program that does not compile will result in a zero.
2.
Runtime error and compilation warning 5%
3.
Commenting and style 15%
4.
Functionality 80%
Programming Style Guidelines
The major purpose of programming style
guidelines is to make programs easy to read and understand.
Good programming style helps make it possible for a person knowledgeable in the application area to
quickly read a program and understand how it works.
1.
Your program should begin with a comment th
at briefly summarizes what it does. This
comment should also include your
name
.
2.
In most cases, a function should have a brief comment above its definition describing what it
does. Other than that, comments should be written only
needed
in order for a rea
der to
understand what is happening.
3.
Variable names and function names should be sufficiently descriptive that a knowledgeable
reader can easily understand what the variable means and what the function does. If this is not
possible, comments should be add
ed to make the meaning clear.
4.
Use consistent indentation to emphasize block structure.
5.
Full line comments inside function bodies should conform to the indentation of the code where
they appear.
6.
Macro definitions (#define) should be used for defining symb
olic names for numeric constants.
For example:
#define PI 3.1
41592
7.
Use names of moderate length for variables. Most names should be between 2 and 12 letters
long.
8.
Use underscores to make compound names easier to read:
tot_vol
or
total_volumn
is
clearer than totalvolumn.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
