Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** SOLUTIONS ***/
- /** PROBLEM 1A **/
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- //Local Declarations
- double base = 0.0;
- double area = 0.0;
- //Local Statements
- //prompt user
- printf("Enter in a value for the base of a square.\n");
- //get input
- scanf("%lf", &base);
- //process data
- area = pow(base, 2);
- //output information
- printf("The area of a square is %8.2lf\n", area);
- return 0;
- }//end main
- /** PROBLEM 1B **/
- #include <stdio.h>
- #include <math.h>
- double ComputeAreaOfSquare(double);
- int main(void)
- {
- //Local Declarations
- double base = 0.0;
- double area = 0.0;
- //Local Statements
- //prompt user
- printf("Enter in a value for the base of a square.\n");
- //get input
- scanf("%lf", &base);
- //process data by calling your function
- area = ComputeAreaOfSquare(base);
- //output information
- printf("The area of a square is %8.2lf\n", area);
- return 0;
- }//end main
- //You would write function descriptions here
- double ComputeAreaOfSquare(double baseIn)
- {
- double area = pow(baseIn,2);
- return area;
- }//end function
- /** PROBLEM 1C **/
- #include <stdio.h>
- #include <math.h>
- void PrintInstructions(void);
- double GetInput(void);
- double ComputeAreaOfSquare(double);
- void PrintOutput(double);
- int main(void)
- {
- //Local Declarations
- double base = 0.0;
- double area = 0.0;
- //Local Statements
- PrintInstructions();
- base = GetInput();
- area = ComputeAreaOfSquare(base);
- PrintOutput(area);
- return 0;
- }//end main
- //You would write function descriptions here
- void PrintInstructions()
- {
- printf("Enter in a value for the base of a square.\n");
- return;
- }//end function
- //You would write function descriptions here
- double GetInput()
- {
- double baseIn = 0.0;
- scanf("%lf", &baseIn);
- return baseIn;
- }//end function
- //You would write function descriptions here
- double ComputeAreaOfSquare(double baseIn)
- {
- double area = pow(baseIn, 2);
- return area;
- }//end function
- void PrintOutput(double areaIn)
- {
- printf("The area of a square is %8.2lf\n",areaIn);
- return;
- }//end function
- /** PROBLEM 2 **/
- #include <stdio.h>
- #include <math.h>
- double CalcHypotenuse(double, double);
- double CalcArea(double, double);
- double CalcPerimeter(double, double, double);
- int main(void)
- {
- //Local Decalarations
- double sideA = 0.0;
- double sideB = 0.0;
- double area = 0.0;
- double perimeter = 0.0;
- //Local Statements
- printf("Enter in values for side A and side B of a right triangle: ");
- scanf("%lf %lf", &sideA, &sideB);
- area = CalcArea(sideA, sideB);
- perimeter = CalcPerimeter(sideA, sideB, CalcHypotenuse(sideA, sideB));
- printf("The Area is: %10.2lf and the perimeter is: %10.2lf\n", area, perimeter);
- return 0;
- }//end main
- double CalcHypotenuse(double sideA, double sideB)
- {
- double hypot = 0.0;
- hypot = sqrt( (pow(sideA,2) + pow(sideB,2)) );
- return hypot;
- }
- double CalcArea(double sideA, double sideB)
- {
- double area = 0.0;
- area = .5 * (sideA * sideB);
- return area;
- }
- double CalcPerimeter(double sideA, double sideB, double sideC)
- {
- double perimeter = sideA + sideB + sideC;
- return perimeter;
- }
- /** PROBLEM 3 **/
- /***********************************************
- * This program demonstrates seeding the random
- * number function.
- * By: Larry Snedden
- * *********************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- //srand(time(NULL));
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- printf("%d\n", rand());
- return 0;
- }//end main
- /** PROBLEM 4 **/
- /****************************************
- * This program is used to demonstrate *
- * The random number functions in *
- * stdlib.h *
- * By: L. Snedden *
- * *************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- srand(time(NULL));//This makes the set random
- //produce numbers ranging from 10 to 20
- //rand() % ((max - min) +1) + 10; //set the range and then shift to the right
- printf(" %d\n", rand() % 11 + 10);
- printf(" %d\n", rand() % 11 + 10);
- printf(" %d\n", rand() % 11 + 10);
- return 0;
- }//end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement