|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
||||
|
||||
|
You actually have to know what you are doing. No instructor and no good grade can guarantee that. Only thinking well can guarantee that. If that doesn't fit your profile, you should look for another field. The programming ranks are already filled with costly failures.
__________________
Write no code whose complexity leaves you wondering what the hell you did. Politically Incorrect DaWei on Pointers Grumpy on Exceptions |
|
#17
|
|||
|
|||
|
What the hell are you talking about? I've already posted a question.
|
|
#18
|
||||
|
||||
|
I'm talking about for real. You're talking about faking it with limited knowledge.
|
|
#19
|
|||
|
|||
|
OK.
If anyone feels that they can help me with my program, I'll appreciate it. |
|
#20
|
|||
|
|||
|
Isn't your code working ? I think you forgot that the sign is altering. ?
|
|
#21
|
|||
|
|||
|
Yes, it is.
Do you mean switching Code:
element=(sin(n*x))/pow(n,3); Code:
element=(sin(n*x)*pow(-1,n))/pow(n,3); |
|
#22
|
|||
|
|||
|
You are incrementing n before calculating element. Shouldn't it be after ?
|
|
#23
|
|||
|
|||
|
Yep. So switch
Code:
n=n+1;
element=(sin(n*x))/pow(n,3);
to Code:
element=(sin(n*x))*pow(-1,n)/pow(n,3); n=n+1; |
|
#24
|
||||
|
||||
|
Because you are using pow(), you should probably use doubles, not floats. Other than that and the inconsistent use of indentation, it looks like you got most of the algorithm down. I just have one question regarding this loop conditional:
(element > 1e-8 || element < -1e-8) What is the meaning of (element == 1e-8 || element == -1e-8) ? I am not saying this is wrong, I was just wondering what logic led you to use these magic numbers to terminate your loop?
__________________
My worst nightmare was a pointless infinite loop. Work in progress; don't poke the curmudgeon! http://www.odonahue.com/ |
|
#25
|
|||
|
|||
|
Quote:
To be frankly - I have no idea. On the beginning, I had just the first part, but then I've shown this code to some experienced guy who works as a programmmer. By the time I realized that change he made, he has already been away. You're talking about inconsistent use of paragraphs and brackets. Could you (or maybe someone else) point me out what exactly should I improve? ![]() |
|
#26
|
|||
|
|||
|
Do you have any idea why this program isn't working for x=3 or x=-3?
|
|
#27
|
||||
|
||||
|
Quote:
You might start by defining what "isn't working" means. |
|
#28
|
|||
|
|||
|
When I run the program, enter 3, it returns 'Enter the value of x. It must be between -pi and pi'.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > [C] sum of the series - loop? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|