ruzmora_jorge_hw4

# ruzmora_jorge_hw4 - Page 2 Chapter4 Problem 31 This program...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 //* Chapter 3 Problem 26 */ /* This program will calculate the roots of a quadratic equation */ #include <stdio.h> #include <math.h> int main(void) { /*Declare and initialize variables */ double aa, bb, cc, disc, root1, root2 /* Enter coefficients for equation */ printf("Enter coefficient for a : \n") printf("Enter coefficient for b : \n") printf("Enter coeficient for c : \n") /* Check if real roots exist */ disc = bb * bb - 4 * aa * cc if ( disc > 0.0 ) { disc = sqrt( disc ) root1 = ( -bb + disc ) / ( 2 * aa ) root2 = ( -bb - disc ) / ( 2 * aa ) printf("1st real root found: %.4lf \n\n", root1) printf("2nd real root found: %.4lf \n\n", root2) } else { printf("No real roots were found\n\n") } /*Pause program*/ getchar() getchar() /*Exit program */ return 0 }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sheet1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Page 2 /* Chapter4 Problem 31*/ /* This program calculates an approximation of factorial using the Stirling formula*/ #include <math.h> #include <stdio.h> #define e 2.718282 #define PI 3.141593 int main(void) { /*Declare and initialize variables and function prototypes */ int n int n_fact(int n) /*User input of desired factorial number */ printf("Enter value: \n") scanf("%i", &n) /*Compute and calculate factorial*/ printf("Factorial: %i \n",n_fact(n)) /*Pause program */ getchar() getchar() /*Exit program*/ return 0 } /*-------------------------------------*/ /* This function computes a factorial using Stirling formula*/ int n_fact(int n) { /*Declare variables*/ int fact /*Calculate factorial*/ fact = sqrt(2.0*PI*n)* pow(n/e,n) /*Return factorial*/ return fact }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

ruzmora_jorge_hw4 - Page 2 Chapter4 Problem 31 This program...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online