|
Silkroad Online
|
Silkroad Forums
|
Affiliates
|



|
|
View unanswered posts | View active topics
Author |
Message |
pipigrande
|
Post subject: Programming using C Posted: Fri Oct 26, 2007 8:54 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
Sup guys, Just wondering if there are any person out there that knows how to write a program using C?
Im kinda noob at this and I have a big assignment due on sunday o.O...
Tried readin my textbook and everything but I dont get it
Like i understand the basics such as printf and scanf and stuff like that... but when it comes down to using nefted loops and ifs... i get lost. I tried using internet to help, but nothing.
Basically i have to write a program, and type the equation of a parabola and then make the program be able to find the maximun and minimun points. Like my professor wrote this: Find the minimum value or maximun value of y for all values of x between -20.0 and +20.0 in increments of 0.01.
>.<
Anyone help?
Thanks
Last edited by pipigrande on Fri Oct 26, 2007 9:05 pm, edited 1 time in total.
|
|
Top |
|
 |
Innovacious
|
Post subject: Re: Programming using C+ Posted: Fri Oct 26, 2007 8:58 pm |
|
Advanced Member |
 |
 |
Joined: Sep 2006 Posts: 2446 Location:
|
pipigrande wrote: Sup guys, Just wondering if there are any person out there that knows how to write a program using C+? Im kinda noob at this and I have a big assignment due on sunday o.O... Tried readin my textbook and everything but I dont get it Like i understand the basics such as printf and scanf and stuff like that... but when it comes down to using nexted loops and ifs... i get lost. I tried using internet to help, but nothing. >.< Anyone help? Thanks
its C++, and nexted loops? Its nested, as in one loop is nested inside another (you changed it to nefted while i was replying, still wrong  ) . By the sounds of it you are screwed. Also, you havnt actually told us what you need to do so we cant help
_________________

|
|
Top |
|
 |
pipigrande
|
Post subject: Re: Programming using C+ Posted: Fri Oct 26, 2007 9:03 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
Innovacious wrote: pipigrande wrote: Sup guys, Just wondering if there are any person out there that knows how to write a program using C+? Im kinda noob at this and I have a big assignment due on sunday o.O... Tried readin my textbook and everything but I dont get it Like i understand the basics such as printf and scanf and stuff like that... but when it comes down to using nexted loops and ifs... i get lost. I tried using internet to help, but nothing. >.< Anyone help? Thanks its C++, and nexted loops? Its nested, as in one loop is nested inside another (you changed it to nefted while i was replying, still wrong  ) . By the sounds of it you are screwed. Also, you havnt actually told us what you need to do so we cant help
Yeah, you are right. I mean loops inside another loops. So nested loops.
I am not using C++. I use the other one simpler than this one, which we call C+ or simply C.
Oh yea.. i forgot to say wat the assignment was... sorry.
I will post it in the post.. take a look at it 
|
|
Top |
|
 |
micheal_safian
|
Post subject: Re: Programming using C+ Posted: Fri Oct 26, 2007 9:03 pm |
|
Common Member |
 |
 |
Joined: Dec 2006 Posts: 106 Location:
|
pipigrande wrote: Sup guys, Just wondering if there are any person out there that knows how to write a program using C+? Im kinda noob at this and I have a big assignment due on sunday o.O... Tried readin my textbook and everything but I dont get it Like i understand the basics such as printf and scanf and stuff like that... but when it comes down to using nefted loops and ifs... i get lost. I tried using internet to help, but nothing. >.< Anyone help? Thanks
i can help u out if u tell me exactly what u need ..and yeah it's called nested loop where u make a loop inside another
|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Fri Oct 26, 2007 9:12 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
I sent you a pm micheal, with the exact specifications to see if you can help.
I dont think i should copy and paste the exact specifications, cus that might get other 'novice' C programmers confused.
So, I was just asking something not so simple to see if people could help me out here.
Anyways... if anyone else wanna help, please do so
Thanks
|
|
Top |
|
 |
Innovacious
|
Post subject: Re: Programming using C Posted: Fri Oct 26, 2007 9:17 pm |
|
Advanced Member |
 |
 |
Joined: Sep 2006 Posts: 2446 Location:
|
pipigrande wrote: Basically i have to write a program, and type the equation of a parabola and then make the program be able to find the maximun and minimun points. Like my professor wrote this: Find the minimum value or maximun value of y for all values of x between -20.0 and +20.0 in increments of 0.01. >.<
Anyone help?
Thanks
lol, its 10pm and i dont feel like working out algorithms right now unless i really have to. I suppose for the main part of it you will need to loop while incrementing x. something like this maybe
Code: for(x=-20;x<=20;x=x+0.01) { }
been a few months since ive done any C programming :\
_________________

|
|
Top |
|
 |
pipigrande
|
Post subject: Re: Programming using C Posted: Fri Oct 26, 2007 9:21 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
Innovacious wrote: pipigrande wrote: Basically i have to write a program, and type the equation of a parabola and then make the program be able to find the maximun and minimun points. Like my professor wrote this: Find the minimum value or maximun value of y for all values of x between -20.0 and +20.0 in increments of 0.01. >.<
Anyone help?
Thanks lol, its 10pm and i dont feel like working out algorithms right now unless i really have to. I suppose for the main part of it you will need to loop while incrementing x. something like this maybe Code: for(x=-20;x<=20;x=x+0.01) { } been a few months since ive done any C programming :\
C programming is soooo hard. It's like learning another language.
Ya, i was almost thinking the same thing. But shouldnt it be:
for( x=-20;x<=20;x=0.01) ??
|
|
Top |
|
 |
Innovacious
|
Post subject: Re: Programming using C Posted: Fri Oct 26, 2007 9:23 pm |
|
Advanced Member |
 |
 |
Joined: Sep 2006 Posts: 2446 Location:
|
pipigrande wrote: Innovacious wrote: pipigrande wrote: Basically i have to write a program, and type the equation of a parabola and then make the program be able to find the maximun and minimun points. Like my professor wrote this: Find the minimum value or maximun value of y for all values of x between -20.0 and +20.0 in increments of 0.01. >.<
Anyone help?
Thanks lol, its 10pm and i dont feel like working out algorithms right now unless i really have to. I suppose for the main part of it you will need to loop while incrementing x. something like this maybe Code: for(x=-20;x<=20;x=x+0.01) { } been a few months since ive done any C programming :\ C programming is soooo hard. It's like learning another language. Ya, i was almost thinking the same thing. But shouldnt it be: for( x=-20;x<=20;x=0.01) ??
that would make x equal 0.01 after every loop, and would cause that to fall into an infinite loop. You want x to equal what it already equals plus the extra 0.01.
_________________

|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Fri Oct 26, 2007 10:04 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
micheal_safian wrote:
I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused  .. Thanks for helping though
I never knew programming was so hard... O M G
|
|
Top |
|
 |
micheal_safian
|
Post subject: Posted: Fri Oct 26, 2007 10:14 pm |
|
Common Member |
 |
 |
Joined: Dec 2006 Posts: 106 Location:
|
pipigrande wrote: micheal_safian wrote: I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused  .. Thanks for helping though I never knew programming was so hard... O M G
man while loop is pretty easy to understand and it fits in ur situation here as u don't need a nested for loop ...the while loop i wrote is the exact u need ..if u can't understand it copy and paste it but be careful with the variables names. While loop is all about a condition in the first and iterating in the body of it ..that's all...  how many classes did u take in programming man ?????
|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Fri Oct 26, 2007 10:30 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
micheal_safian wrote: pipigrande wrote: micheal_safian wrote: I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused  .. Thanks for helping though I never knew programming was so hard... O M G man while loop is pretty easy to understand and it fits in ur situation here as u don't need a nested for loop ...the while loop i wrote is the exact u need ..if u can't understand it copy and paste it but be careful with the variables names. While loop is all about a condition in the first and iterating in the body of it ..that's all...  how many classes did u take in programming man ?????
How many?... Let me think.. this is a hard question... This is my first class!
Have never taken it before =S... but i need it in order to pass the course.
Need help >.>
|
|
Top |
|
 |
micheal_safian
|
Post subject: Posted: Fri Oct 26, 2007 10:46 pm |
|
Common Member |
 |
 |
Joined: Dec 2006 Posts: 106 Location:
|
pipigrande wrote: micheal_safian wrote: pipigrande wrote: micheal_safian wrote: I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused  .. Thanks for helping though I never knew programming was so hard... O M G man while loop is pretty easy to understand and it fits in ur situation here as u don't need a nested for loop ...the while loop i wrote is the exact u need ..if u can't understand it copy and paste it but be careful with the variables names. While loop is all about a condition in the first and iterating in the body of it ..that's all...  how many classes did u take in programming man ????? How many?... Let me think.. this is a hard question... This is my first class! Have never taken it before =S... but i need it in order to pass the course. Need help >.>
this is foolish thing to give such a task in ur first class..... 
|
|
Top |
|
 |
NuclearSilo
|
Post subject: Posted: Fri Oct 26, 2007 11:39 pm |
|
Forum God |
 |
 |
Joined: Aug 2006 Posts: 8834 Location: Age of Wushu
|
isnt max or min = f(-2b/a)?
_________________ Playing Age of Wushu, dota IMBA
|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Sat Oct 27, 2007 4:45 am |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
NuclearSilo wrote: isnt max or min = f(-2b/a)?
wat?
|
|
Top |
|
 |
Cruor
|
Post subject: Posted: Sat Oct 27, 2007 6:10 am |
|
Loyal Member |
 |
 |
Joined: Apr 2006 Posts: 1999 Location:
|
It sounds to me like he wants you to differentiate f(x) then output a table of values for f'(x) in increments of 0.01
I also assume since you mentioned a parabola that you will only be dealing with quadratic functions. Therefore, you can simply ask the user for a, b, and c. For the function f(x)=5x^2+2x-3, a is 5, b is 2, and c is -3. Of course, the derivative is simply f'(x)=10x+2 so there is nothing difficult to do there. After you've got the derivative all you have to do is plug in numbers for x and print the results. The extrema are of course wherever f'(x)=0
Here's a quickie I wrote:
Code: #include <stdio.h>
int main() { int a; int b; int c; float i; float y;
printf ("f(x)=ax^2+bx+c\n\n"); printf ("Enter a: "); scanf ("%d", &a); printf ("Enter b: "); scanf ("%d", &b); printf ("Enter c: "); scanf ("%d", &c);
a *= 2;
printf ("\nf'(x)=%dx+%d\n\n", a, b);
for (i=-20; i<=20; i+=0.01) { y = a*i+b; printf("f'(%f)=%f\n", i, y);}
return 0;}
You'll probably have to tweak it to meet your specific needs (possibly error checking and truncation on the floats if it's expected) but that should give you a start. Hope this helped.
If nested loops confuse you I bet you'll have fun with recursive functions. 
_________________
|
|
Top |
|
 |
micheal_safian
|
Post subject: Posted: Sat Oct 27, 2007 8:05 am |
|
Common Member |
 |
 |
Joined: Dec 2006 Posts: 106 Location:
|
Cruor wrote: It sounds to me like he wants you to differentiate f(x) then output a table of values for f'(x) in increments of 0.01 I also assume since you mentioned a parabola that you will only be dealing with quadratic functions. Therefore, you can simply ask the user for a, b, and c. For the function f(x)=5x^2+2x-3, a is 5, b is 2, and c is -3. Of course, the derivative is simply f'(x)=10x+2 so there is nothing difficult to do there. After you've got the derivative all you have to do is plug in numbers for x and print the results. The extrema are of course wherever f'(x)=0 Here's a quickie I wrote: Code: #include <stdio.h>
int main() { int a; int b; int c; float i; float y;
printf ("f(x)=ax^2+bx+c\n\n"); printf ("Enter a: "); scanf ("%d", &a); printf ("Enter b: "); scanf ("%d", &b); printf ("Enter c: "); scanf ("%d", &c);
a *= 2;
printf ("\nf'(x)=%dx+%d\n\n", a, b);
for (i=-20; i<=20; i+=0.01) { y = a*i+b; printf("f'(%f)=%f\n", i, y);}
return 0;} You'll probably have to tweak it to meet your specific needs (possibly error checking and truncation on the floats if it's expected) but that should give you a start. Hope this helped. If nested loops confuse you I bet you'll have fun with recursive functions. 
nice work ...lol...i didn't think that parabola is calc thing .....lol..i coded it fro him but as just an equation. 
|
|
Top |
|
 |
NuclearSilo
|
Post subject: Posted: Sat Oct 27, 2007 12:03 pm |
|
Forum God |
 |
 |
Joined: Aug 2006 Posts: 8834 Location: Age of Wushu
|
Cruor wrote: It sounds to me like he wants you to differentiate f(x) then output a table of values for f'(x) in increments of 0.01 I also assume since you mentioned a parabola that you will only be dealing with quadratic functions. Therefore, you can simply ask the user for a, b, and c. For the function f(x)=5x^2+2x-3, a is 5, b is 2, and c is -3. Of course, the derivative is simply f'(x)=10x+2 so there is nothing difficult to do there. After you've got the derivative all you have to do is plug in numbers for x and print the results. The extrema are of course wherever f'(x)=0 Here's a quickie I wrote: Code: #include <stdio.h>
int main() { int a; int b; int c; float i; float y;
printf ("f(x)=ax^2+bx+c\n\n"); printf ("Enter a: "); scanf ("%d", &a); printf ("Enter b: "); scanf ("%d", &b); printf ("Enter c: "); scanf ("%d", &c);
a *= 2;
printf ("\nf'(x)=%dx+%d\n\n", a, b);
for (i=-20; i<=20; i+=0.01) { y = a*i+b; printf("f'(%f)=%f\n", i, y);}
return 0;} You'll probably have to tweak it to meet your specific needs (possibly error checking and truncation on the floats if it's expected) but that should give you a start. Hope this helped. If nested loops confuse you I bet you'll have fun with recursive functions. 
Are u kidding?
U dont need the derivative in order to find the extrema. For all parabola type f(x) = ax²+bx+c:
extrema = f(-b/(2a))
_________________ Playing Age of Wushu, dota IMBA
|
|
Top |
|
 |
Jstar1
|
Post subject: Posted: Sat Oct 27, 2007 2:33 pm |
|
Senior Member |
 |
 |
Joined: Mar 2007 Posts: 4757 Location:
|
what is it, college or a high school class? cause I don't think we have programming at our high school
_________________
|
|
Top |
|
 |
Cruor
|
Post subject: Posted: Sat Oct 27, 2007 4:10 pm |
|
Loyal Member |
 |
 |
Joined: Apr 2006 Posts: 1999 Location:
|
NuclearSilo wrote: Are u kidding? U dont need the derivative in order to find the extrema. For all parabola type f(x) = ax²+bx+c: extrema = f(-b/(2a)) And where do you think that equation came from? (although the way you wrote it, the extrema would be equal to a(-b/2a)²+b(-b/2a)+c)
f(x) = ax²+bx+c
f'(x) = 2ax+b
2ax+b = 0
2ax = -b
x = -b/(2a)
Anyway, the problem with it is that it doesn't satisfy the requirements of the assignment. He needs to output values for f'(x) where -20≤x≤20. Whether the extrema is in that range doesn't matter. He can't just calculate the extrema using that shortcut.
_________________
|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Sat Oct 27, 2007 4:37 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
Cruor wrote: Code: #include <stdio.h>
int main() { int a; int b; int c; float i; float y;
printf ("f(x)=ax^2+bx+c\n\n"); printf ("Enter a: "); scanf ("%d", &a); printf ("Enter b: "); scanf ("%d", &b); printf ("Enter c: "); scanf ("%d", &c);
a *= 2 printf ("\nf'(x)=%dx+%d\n\n", a, b);
for (i=-20; i<=20; i+=0.01) { y = a*i+b; printf("f'(%f)=%f\n", i, y);}
return 0;} Ok, first of all, thanks everyone for trying to help me.. I really appreaciate it  . Now, could anyone explain wat does a *= 2 part on cruor program means?... Also, taking a look in the program it seems, that the program will keep looping from i=-20 until i reaches equal to 19 (20 is not included - i suppose). But, then i dont want to find all the vallues in between -20 and 20. How should I write the program so, it just gives me the maximun point and the minimun point (at -20 and 20). Do you guys understand what im trying to say? If not I could type the specific intructioons the prof gave me. Jstar1 wrote: what is it, college or a high school class? cause I don't think we have programming at our high school
I am at Ryerson University, and my program is biology. In high school, I never took programming, but for the university ALL first year science students must take the course. Also, the university expect us to know some basic programming stuff, since we were supposed to take it in high school, but my high school didnt offer the course.
This is pretty much new to me, and trust me ITS HARD. I read 2 books on this stuff, and i dont really understand anything...
|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Sat Oct 27, 2007 4:41 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
Well, I think I am gonna copy and paste the specific intructioons, so you guys know what I am talking about.
So, here it goes:
What to do:
The equation of the parabola is y = ax² + bx + c Write a complete C program capable of finding the maximum or minimum of a parabola. As input, the program is to ask the user data consisting of the values of a, b and c for the parabola. Find the minimum value (or maximum depending on the parabola) of y for all values of x between -20.0 and +20.0 in increments of 0.01. Your program must produce a nicely aligned report. Display the minimum/maximum value of y and the value of x at that point. Display your name(s) at the bottom of the report. Your code must have good style including comments and proper indentation. All numerical values on the report must come from variables, not constants.
|
|
Top |
|
 |
Cruor
|
Post subject: Posted: Sat Oct 27, 2007 5:08 pm |
|
Loyal Member |
 |
 |
Joined: Apr 2006 Posts: 1999 Location:
|
pipigrande wrote: explain wat does a *= 2 It's shorthand for: Code: a = a * 2 pipigrande wrote: the program will keep looping from i=-20 until i reaches equal to 19 (20 is not included - i suppose) No, 20 is included because the condition is less-than-or-equal-to: Code: x <= 20 My solution basically meets all his requirements, although I have no idea what is he talking about when he says: Quote: Find the minimum value (or maximum depending on the parabola) of y for all values of x Parabolas only have one extrema, therefore there won't be an extrema for every point on the parabola. That is why I took the derivative approach.
_________________
|
|
Top |
|
 |
NuclearSilo
|
Post subject: Posted: Sat Oct 27, 2007 5:36 pm |
|
Forum God |
 |
 |
Joined: Aug 2006 Posts: 8834 Location: Age of Wushu
|
Cruor wrote: NuclearSilo wrote: Are u kidding? U dont need the derivative in order to find the extrema. For all parabola type f(x) = ax²+bx+c: extrema = f(-b/(2a)) And where do you think that equation came from? (although the way you wrote it, the extrema would be equal to a(-b/2a)²+b(-b/2a)+c) f(x) = ax²+bx+c f'(x) = 2ax+b 2ax+b = 0 2ax = -b x = -b/(2a) Anyway, the problem with it is that it doesn't satisfy the requirements of the assignment. He needs to output values for f'(x) where -20≤x≤20. Whether the extrema is in that range doesn't matter. He can't just calculate the extrema using that shortcut. Whatever... In my school, the formula of the extrema is acquired automatically, it means that u can use it and u dont need to demonstrate through the derivative. Code: #include <stdio.h>
int main() { int a; int b; int c; float i; float y;
printf ("f(x)=ax^2+bx+c\n\n"); printf ("Enter a: "); scanf ("%d", &a); printf ("Enter b: "); scanf ("%d", &b); printf ("Enter c: "); scanf ("%d", &c);
a *= 2 printf ("\nf'(x)=%dx+%d\n\n", a, b);
for (i=-20; i<=20; i+=0.01) { y = a*i+b; printf("f'(%f)=%f\n", i, y);}
return 0;} This code calculate f'(x) from x=-20 to x=+20, which is not what the exercise tell u to do. Quote: What to do: The equation of the parabola is y = ax² + bx + c Write a complete C program capable of finding the maximum or minimum of a parabola. As input, the program is to ask the user data consisting of the values of a, b and c for the parabola. Find the minimum value (or maximum depending on the parabola) of y for all values of x between -20.0 and +20.0 in increments of 0.01. Your program must produce a nicely aligned report. Display the minimum/maximum value of y and the value of x at that point. Display your name(s) at the bottom of the report. Your code must have good style including comments and proper indentation. All numerical values on the report must come from variables, not constants.
If u read carefully again, u have to calculate f(x) and then give the max or min between those value. Because extrema can be located out of the range of -20,20 so u cant absolutely use the derivative.
_________________ Playing Age of Wushu, dota IMBA
|
|
Top |
|
 |
andrejat
|
Post subject: Posted: Sat Oct 27, 2007 5:45 pm |
|
Banned User |
 |
Joined: Jul 2007 Posts: 626 Location:
|
*reads all above posts*
Hah, forget taking C programming next year xD No wonder you need calculus at my school to even start.
|
|
Top |
|
 |
Cruor
|
Post subject: Posted: Sat Oct 27, 2007 5:51 pm |
|
Loyal Member |
 |
 |
Joined: Apr 2006 Posts: 1999 Location:
|
NuclearSilo wrote: If u read carefully again, u have to calculate f(x) and then give the max or min between those value. Because extrema can be located out of the range of -20,20 so u cant absolutely use the derivative. I'm reading it, and it's hard to tell what the professor is asking for. If he just wants the extrema then why does he say this? Quote: Find the minimum value (or maximum depending on the parabola) of y for all values of x between -20.0 and +20.0 in increments of 0.01. It's like he's asking for more than one extrema, which doesn't make sense. If he just wants the extrema he would just ask that it be calculated and then checked for the bounds -20≤x≤20, but you wouldn't use increments of x for that.
Anyway, if he is asking for the derivative method, I fixed that earlier program up a bit so that it meets his instructions.
Code: #include <stdio.h>
int main() { /* declare variables */ int a; int b; int c; float i; float y;
/* request user input */ printf("y = ax\xFD + bx + c\n\n"); printf("Enter a: "); scanf("%d", &a); printf("Enter b: "); scanf("%d", &b); printf("Enter c: "); scanf("%d", &c);
/* differentiate a */ a*=2;
/* print the derivative */ printf("\nThe derivative is:\ndy/dx (x) = (%dx) + (%d)\n\n", a, b);
for(i=-20; i<=20; i+=0.01) { /* calculate the value of the derivative at x */ y = a*i+b; /* print the results */ printf("dy/dx (%.2f) = %.2f\n", i, y); }
/* print my name */ printf("\nFirstname Lastname");
return 0; }
_________________
|
|
Top |
|
 |
NuclearSilo
|
Post subject: Posted: Sat Oct 27, 2007 6:24 pm |
|
Forum God |
 |
 |
Joined: Aug 2006 Posts: 8834 Location: Age of Wushu
|
Cruor wrote: NuclearSilo wrote: If u read carefully again, u have to calculate f(x) and then give the max or min between those value. Because extrema can be located out of the range of -20,20 so u cant absolutely use the derivative. I'm reading it, and it's hard to tell what the professor is asking for. If he just wants the extrema then why does he say this? Quote: Find the minimum value (or maximum depending on the parabola) of y for all values of x between -20.0 and +20.0 in increments of 0.01. It's like he's asking for more than one extrema, which doesn't make sense. If he just wants the extrema he would just ask that it be calculated and then checked for the bounds -20≤x≤20, but you wouldn't use increments of x for that. Anyway, if he is asking for the derivative method, I fixed that earlier program up a bit so that it meets his instructions. Code: #include <stdio.h>
int main() { /* declare variables */ int a; int b; int c; float i; float y;
/* request user input */ printf("y = ax\xFD + bx + c\n\n"); printf("Enter a: "); scanf("%d", &a); printf("Enter b: "); scanf("%d", &b); printf("Enter c: "); scanf("%d", &c);
/* differentiate a */ a*=2;
/* print the derivative */ printf("\nThe derivative is:\ndy/dx (x) = (%dx) + (%d)\n\n", a, b);
for(i=-20; i<=20; i+=0.01) { /* calculate the value of the derivative at x */ y = a*i+b; /* print the results */ printf("dy/dx (%.2f) = %.2f\n", i, y); }
/* print my name */ printf("\nFirstname Lastname");
return 0; }
lol
It's not the extrema he wants, but the min or max between values.
_________________ Playing Age of Wushu, dota IMBA
|
|
Top |
|
 |
Cruor
|
Post subject: Posted: Sat Oct 27, 2007 8:06 pm |
|
Loyal Member |
 |
 |
Joined: Apr 2006 Posts: 1999 Location:
|
NuclearSilo wrote: It's not the extrema he wants, but the min or max between values. Extrema is just plural for minima and maxima. Like I said, if he just wanted an extrema within the bounds -20≤x≤20 then the assignment would have been to calculate the extrema (which I may add could be done with derivatives as well as the shortcut, how it is done wouldn't matter in that case) and then check to see if it is within those bounds.
Here is what a program that uses your interpretation looks like: Code: #include <stdio.h>
int main() { /* declare variables */ float a, b, c, x, y;
/* request user input */ printf("y=ax\xFD+bx+c\n\n"); printf("Enter a: "); scanf("%f", &a); printf("Enter b: "); scanf("%f", &b); printf("Enter c: "); scanf("%f", &c);
/* find the extrema */ x = (-1*b)/(2*a);
/* calculate y at extrema */ y = a*x*x+b*x+c;
/* check extrema against bounds */ if(x>=-20 && x<=20) printf("\nx=%.2f\ny=%.2f\n", x, y); else printf("\nThere is no extrema within the bounds -20\xF3x%s20\n", "\xF3") ;
/* print my name */ printf("\nFirstname Lastname");
return 0; } And here's the derivative method: Code: #include <stdio.h>
int main() { /* declare variables */ float a, b, c, i, d, y;
/* request user input */ printf("y=ax\xFD+bx+c\n\n"); printf("Enter a: "); scanf("%f", &a); printf("Enter b: "); scanf("%f", &b); printf("Enter c: "); scanf("%f", &c);
/* print the derivative */ printf("\nThe derivative is:\ndy/dx (x)=%.2fx%+.2f\n\n", a*2, b);
for(i=-20; i<=20; i+=0.01) { /* calculate the value of the derivative at x */ d = a*2*i+b; /* calculate y at x */ y = (a*i*i)+(b*i)+c; /* print the results */ printf("dy/dx (%.2f)=%.2f; y=%.2f\n", i, d, y); }
/* print my name */ printf("\nFirstname Lastname");
return 0; } Compare the if/else statement in the first program to the for loop in the second program. The if/else statement has nothing to do with increments of 0.01 while the for loop does. That is why I think he wanted the second solution. Rereading it, I also realized that the y values should be printed as well. In the first program the output looks like: Code: x=0.20 y=2.80 Or, if the extrema doesn't exist within the bounds: Code: There is no extrema within the bounds -20≤x≤20 The output of the second program looks like: Code: dy/dx (0.20)=0.00; y=2.80
Regardless of what his professor meant, the OP is now covered in either situation so I suppose it doesn't matter past that.
_________________
|
|
Top |
|
 |
pipigrande
|
Post subject: Posted: Sat Oct 27, 2007 9:12 pm |
|
Active Member |
 |
 |
Joined: Jul 2006 Posts: 688 Location: Canada
|
WOW, thanks Cruor and NuclearSilo... those programs are gonna help me a lot.
Now im gonna copy them in the program which I will dowload tonight and see how it works. (Program's Name: Quincy).
Really Thankgful guys...
See, now I will probably wont fail the course. I had my 1st midterm and i got 96%, and the 2nd midterm i got 60% (this one had problems similar to this assignment). This assignment is suppose to cover 20% of my final mark... now gotta study for the final exam (this gonna be a killer).
Thanks again guys... you saved my ass!.
Cookies?!! 
|
|
Top |
|
 |
[SD]happynoobing
|
Post subject: Posted: Sat Oct 27, 2007 9:14 pm |
|
Advanced Member |
 |
 |
Joined: Jan 2007 Posts: 2349 Location:
|
lol dont ever doubt cruor when it comes to programming xD
_________________
|
|
Top |
|
 |
Who is online |
Users browsing this forum: No registered users and 15 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|