Due February 3, 2002
In part 2 of assignment 1, you described an algorithm to solve quadratic equations. Write a C program that implements the algorithm. Call the program
You should ask the user to type the coefficients after the program starts to run:
Type the coefficients, a b c:
1 3 2.
Your program should print one of these three things (with different numbers, obviously):
There are no real roots.
There is one real root, 2.00.
There are two real roots, -1.00 and 3.00.
All of the values should be stored in variables of type
double. The numbers should be printed with two decimal places.
Here are some things to keep in mind:
#include <math.h>to get the
sqrt()function to take square roots. You also have to add
gcccommand to get it working properly. Like this:
gcc -lm -o quad quad.c
You have to test your program to make sure it works. Actually, you should be testing as you write the program, but all you have to show us is the testing of the finished program.
Get your program from Part 1 working. Then,
script quad.out ./quad (type coefficients with no roots) ./quad (type coefficients with one root) ./quad (type coefficients with two roots) exit
This program will implement a guessing game. The user will enter a number and then another user will try to guess it. Here is a sample run of the program:
1: userid_fruit% ./guess
Enter a number: 102
Take a guess: 50
Sorry, the number was higher than that.
Take a guess: 150
Sorry, the number was lower than that.
Take a guess: 102
Call your program
guess.c . Some notes:
If it doesn't work, don't worry about it (the game won't be as fun, but life will go on). Don't worry, you shouldn't really understand it. [I don't either -Greg]
You have to use the Submission server to submit your work. You should submit the files
You can do this by typing these commands:
tar cvf a2.tar quad.c quad.out guess.c