Silkroad Online Forums

A community forum for the free online game Silkroad Online. Discuss Silkroad Online, read up on guides, and build your character and skills.

Faq Search Members Chat  Register Profile Login

All times are UTC




Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Programming using C
PostPosted: Fri Oct 26, 2007 8:54 pm 
Active Member
User avatar
Offline

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
 Profile  
 
 Post subject: Re: Programming using C+
PostPosted: Fri Oct 26, 2007 8:58 pm 
Advanced Member
User avatar
Offline

Joined: Sep 2006
Posts: 2446
Location:
Off Topic
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 :P ) . By the sounds of it you are screwed. Also, you havnt actually told us what you need to do so we cant help

_________________
ImageImage


Top
 Profile  
 
 Post subject: Re: Programming using C+
PostPosted: Fri Oct 26, 2007 9:03 pm 
Active Member
User avatar
Offline

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 :P ) . 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
 Profile  
 
 Post subject: Re: Programming using C+
PostPosted: Fri Oct 26, 2007 9:03 pm 
Common Member
User avatar
Offline

Joined: Dec 2006
Posts: 106
Location:
Athens
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
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 9:12 pm 
Active Member
User avatar
Offline

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
 Profile  
 
 Post subject: Re: Programming using C
PostPosted: Fri Oct 26, 2007 9:17 pm 
Advanced Member
User avatar
Offline

Joined: Sep 2006
Posts: 2446
Location:
Off Topic
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 :\

_________________
ImageImage


Top
 Profile  
 
 Post subject: Re: Programming using C
PostPosted: Fri Oct 26, 2007 9:21 pm 
Active Member
User avatar
Offline

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
 Profile  
 
 Post subject: Re: Programming using C
PostPosted: Fri Oct 26, 2007 9:23 pm 
Advanced Member
User avatar
Offline

Joined: Sep 2006
Posts: 2446
Location:
Off Topic
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.

_________________
ImageImage


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 9:58 pm 
Common Member
User avatar
Offline

Joined: Dec 2006
Posts: 106
Location:
Athens
man i pmed u with the solution ....read it.I hope i helped :D :D :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:04 pm 
Active Member
User avatar
Offline

Joined: Jul 2006
Posts: 688
Location: Canada
micheal_safian wrote:
man i pmed u with the solution ....read it.I hope i helped :D :D :D


I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused :? :banghead: .. Thanks for helping though :love:

I never knew programming was so hard... O M G


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:14 pm 
Common Member
User avatar
Offline

Joined: Dec 2006
Posts: 106
Location:
Athens
pipigrande wrote:
micheal_safian wrote:
man i pmed u with the solution ....read it.I hope i helped :D :D :D


I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused :? :banghead: .. Thanks for helping though :love:

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... :D :D how many classes did u take in programming man ?????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:30 pm 
Active Member
User avatar
Offline

Joined: Jul 2006
Posts: 688
Location: Canada
micheal_safian wrote:
pipigrande wrote:
micheal_safian wrote:
man i pmed u with the solution ....read it.I hope i helped :D :D :D


I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused :? :banghead: .. Thanks for helping though :love:

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... :D :D 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
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 10:46 pm 
Common Member
User avatar
Offline

Joined: Dec 2006
Posts: 106
Location:
Athens
pipigrande wrote:
micheal_safian wrote:
pipigrande wrote:
micheal_safian wrote:
man i pmed u with the solution ....read it.I hope i helped :D :D :D


I dont understand nested loops... Now u gave me something using 'while loops'... man now im more confused :? :banghead: .. Thanks for helping though :love:

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... :D :D 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..... :shock: :shock: :shock: :shock:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 26, 2007 11:39 pm 
Forum God
User avatar
Offline

Joined: Aug 2006
Posts: 8834
Location: Age of Wushu
isnt max or min = f(-2b/a)?

_________________
Playing Age of Wushu, dota IMBA


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 4:45 am 
Active Member
User avatar
Offline

Joined: Jul 2006
Posts: 688
Location: Canada
NuclearSilo wrote:
isnt max or min = f(-2b/a)?


wat?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 6:10 am 
Loyal Member
User avatar
Offline

Joined: Apr 2006
Posts: 1999
Location:
Off Topic
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. :P

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 8:05 am 
Common Member
User avatar
Offline

Joined: Dec 2006
Posts: 106
Location:
Athens
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. :P


nice work ...lol...i didn't think that parabola is calc thing .....lol..i coded it fro him but as just an equation. :D :D :D :D :D


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 12:03 pm 
Forum God
User avatar
Offline

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. :P

Are u kidding? :roll:
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
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 2:33 pm 
Senior Member
User avatar
Offline

Joined: Mar 2007
Posts: 4757
Location:
Off Topic
what is it, college or a high school class? cause I don't think we have programming at our high school

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 4:10 pm 
Loyal Member
User avatar
Offline

Joined: Apr 2006
Posts: 1999
Location:
Off Topic
NuclearSilo wrote:
Are u kidding? :roll:
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 4:37 pm 
Active Member
User avatar
Offline

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 :love: .

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
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 4:41 pm 
Active Member
User avatar
Offline

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
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:08 pm 
Loyal Member
User avatar
Offline

Joined: Apr 2006
Posts: 1999
Location:
Off Topic
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:36 pm 
Forum God
User avatar
Offline

Joined: Aug 2006
Posts: 8834
Location: Age of Wushu
Cruor wrote:
NuclearSilo wrote:
Are u kidding? :roll:
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
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:45 pm 
Banned User
Offline

Joined: Jul 2007
Posts: 626
Location:
Odin
*reads all above posts*

Hah, forget taking C programming next year xD No wonder you need calculus at my school to even start.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 5:51 pm 
Loyal Member
User avatar
Offline

Joined: Apr 2006
Posts: 1999
Location:
Off Topic
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;
}

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 6:24 pm 
Forum God
User avatar
Offline

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
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 8:06 pm 
Loyal Member
User avatar
Offline

Joined: Apr 2006
Posts: 1999
Location:
Off Topic
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.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 9:12 pm 
Active Member
User avatar
Offline

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?!! :D :love:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 9:14 pm 
Advanced Member
User avatar
Offline

Joined: Jan 2007
Posts: 2349
Location:
Off Topic
lol dont ever doubt cruor when it comes to programming xD

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2  Next

All times are UTC


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group