![]() |
| | #1 |
| Registered User Join Date: Mar 2006
Posts: 6
| Entering in an nth degree polynomial Code: #include <stdio.h>
#include <stdlib.h>
void polynomial(char *);
main()
{
}
void polynomial(char *ptr)
{
int degree;
printf("\nEnter the degree of the polynomial you wish to integrate.");
scanf("%d", °ree);
ptr=(char *)malloc((degree+1) * sizeof(char));
if(ptr= NULL)
{
puts("Memory Allocation Failed.");
}
}
Code: ptr=(char *)malloc((degree+1) * sizeof(char)); |
| Noah is offline | |
| | #2 |
| The Richness... Join Date: Jan 2006 Location: Ireland
Posts: 469
| well what i would do is make your functions return the result of the numerical integration - that way main can compare the two: also you could use the maximum error calculation for simpsons rule and see if the difference between the two methods is less than it - just an aside. also, for reading in the coefficients, they're gonna be integers, not chars - its not that easy to get a computer to do calculations with variable names as opposed to numerical values - dynamically allocate an array of ints, use a loop to read in the correct coefficient into each element and then implement your function - in my own opinion i would think it better to enter the coefficients one by one. your output could look like: Code: Enter degree: 2 Enter the coefficient of x^2: 1 Enter the coefficient of x: 0 Enter constant: 5 The polynomial is: x^2 + 5 print x^1 and x^0? - just something i'd do if i had the time myself) Good luck with implementing the numerical methods, hope i answered your questions. PS - you could avoid memory allocation and just define an array large enough to store a reasonable number of coefficients - say 100. also, it wouldn't increase the complexity if you used double for the coefficients, its up to you, but its always good to give a user the freedom to enter in .87 if they so feel like it (and if the same makes logical sense for the program of course!)
__________________ No No's: fflush (stdin); gets (); void main (); Goodies: Example of fgets (); The FAQ, C/C++ Reference My Gear: OS - Windows XP IDE - MS Visual C++ 2008 Express Edition ASCII stupid question, get a stupid ANSI |
| Richie T is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C program Degree to Radians | Cyberman86 | C Programming | 5 | 05-04-2009 09:34 PM |
| Computing Degree Question | cjwenigma | General Discussions | 2 | 09-17-2007 01:06 PM |
| large polynomial | squeaker | C++ Programming | 2 | 03-22-2006 01:15 AM |
| Polynomial | Unregistered | C++ Programming | 1 | 04-17-2002 05:00 PM |
| Polynomial Problem | softcoder76 | C++ Programming | 5 | 03-01-2002 02:07 PM |