(delete)

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
You're kidding right? How about you try doing the assignment and we'll give you hints when you get stuck.
 

vstypicals

Junior Member
Apr 6, 2004
18
0
0
Originally posted by: igowerf
You're kidding right? How about you try doing the assignment and we'll give you hints when you get stuck.

I'm doing it as we speak. =/ I know how to do most of the stuff. I just don't know how to put them together.. Sorry if that's confusing. Heh.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
make an attempt at putting them together and if it doesn't work we can try to point out how to fix it :)
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Well, you would prompt the user... and if you know calculus, then it shoudl be easy to figure out a basic algorithm. HINT: It involves a loop. :)
 

vstypicals

Junior Member
Apr 6, 2004
18
0
0
Final product... (dont mind the commenting; the professor wanted that stuff.)

--------------------------------------------------------

#include <stdio.h>


/* variable declarations */

double func();
double h, sum;
int i, n;


main()
{
/* prompt the user for the number of iterations (n) */
printf("How many steps? ");
scanf("%d", &n);

sum = 0; /* initialize the sum to 0 */
h = 2.0/n; /* formula for height */

/* loop to add up of the sums */
for(i = 0; i < n; i++)
{
sum += ((h/2.0)*(func(i*h) + func(i*h + h)));

}

/* print results */
printf("The integral approximation from 0 to 2 with %d steps is %f\n", n, sum);
}

/* func - this function computes the square of x
*
* inputs:
* x - the value to be squared
*
* outputs:
* the square of x
*
* side effects:
* none
*/

double func(double x)
{
return x*x;
}
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Originally posted by: vstypicals
Originally posted by: notfred

Here's my windows exe.



See if it gets the same results as yours does ;)



Uh.. It prompts the user for the number of steps.. then exits once it's given.. Or was that a trojan? =/

It probably prompts and the prints the result and immediately closes. It goes by too fast for you to see.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: igowerf
Originally posted by: vstypicals
Originally posted by: notfred

Here's my windows exe.



See if it gets the same results as yours does ;)



Uh.. It prompts the user for the number of steps.. then exits once it's given.. Or was that a trojan? =/

It probably prompts and the prints the result and immediately closes. It goes by too fast for you to see.

seriously. I didn't write a GUI app to do this, run it from a command line and you'll see the result.
 

vstypicals

Junior Member
Apr 6, 2004
18
0
0
Originally posted by: igowerf

It probably prompts and the prints the result and immediately closes. It goes by too fast for you to see.

Yeah, that's what I thought too.
 

vstypicals

Junior Member
Apr 6, 2004
18
0
0
Originally posted by: notfred
Originally posted by: vstypicals
Originally posted by: igowerf



It probably prompts and the prints the result and immediately closes. It goes by too fast for you to see.



Yeah, that's what I thought too.

Works just fine on two different windows machines for me.

Here's the source if you want to compile it yourself.

I just directly ran it.. and it did close too fast right after printing the results for me to see. I didn't run it from a command. Sorry. :(