ruzmora_jorge_hw4

ruzmora_jorge_hw4 - Page 2 /* Chapter4 Problem 31*/ /* This...

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

View Full Document Right Arrow Icon
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 }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Sheet1
Background image of page 2
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 &lt;math.h&gt; #include &lt;stdio.h&gt; #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(&quot;Enter value: \n&quot;) scanf(&quot;%i&quot;, &amp;n) /*Compute and calculate factorial*/ printf(&quot;Factorial: %i \n&quot;,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

This note was uploaded on 05/21/2010 for the course EEL 2161 taught by Professor Lopez during the Spring '10 term at FAU.

Page1 / 2

ruzmora_jorge_hw4 - Page 2 /* Chapter4 Problem 31*/ /* This...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online