C programming question

Scrapster

Diamond Member
Nov 27, 2000
3,746
0
0
How do you store functions into C?

In math we're learning about Taylor Series (power series) and figuring sums general solutions for certain problems. I'm tinkering with the idea of creating a program that will do all the calculating, you just need to give it a function and a few other values (general point, how far to sum up everything, etc..). This is also my 7th week in C class and we've only learned how to store char, double, and int. Is it possible to scanf functions into variables?
 

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
You'd probably have to use arrays of some sort. I'm not sure exactly what you need to store. It may be a little ahead of your experience, unless you know more about C than you have learned.

amish
 

cpl593h

Member
Feb 1, 2001
108
0
0

in c, you can have function pointers that you can kind of "store" functions in. Id just use scheme though.
 

Scrapster

Diamond Member
Nov 27, 2000
3,746
0
0
Examples:

polynomials (x^4 + x^3 + x^2....)
sines
cosines
natural log (ln(x))
exponentials (e^x)
etc..

Maybe I am getting over my head. I'd be more than happy to start out simple though, like using basic polynomials. But I don't think I can store these using int/double/char. Does math.h contain types that can store these?

 

Define the functions as a string
like your fuction name would be "cosines"
That function would be defined like another program before the body of the code comes in.
 

Scrapster

Diamond Member
Nov 27, 2000
3,746
0
0
Oh crap, I hope I'm not confusing anyone. The functions I'm talking about are not the same type you would think about in C.
 

Emulex

Diamond Member
Jan 28, 2001
9,759
1
71
sounds like your trying to define macros? give us an example of what your working on..

don't use functions unless you mean literally "somefunction()" because its confusing.
 

cpl593h

Member
Feb 1, 2001
108
0
0
I think you want to have a C function like:

double Taylor ( function, arg1, arg2 ...)

that takes a function as an arg and calculates the taylor series using that function, right? I think you need to look into fucntion pointers.

found a pretty good tutorial at:

http://www.newty.de/CCPP/FPT/em_fpt.html

Like I said, this would be easiest in a language that treats functions as first-class data like Scheme or LISP.

hope this helps
 

Make a function() , out of one of your mathimatical functions.
Or make your own resource file and then #define it before you code.
 

bhuie

Member
May 30, 2000
35
0
0
Maybe I'm misunderstanding the question, but I think what you guys are suggesting is overkill for what he really wants. Is this the kind of thing you're looking for?

int x-squared(int n){
int i;
int sum=0;
for(i=0; i<=n; i++){
sum += i*i;
}
return sum;
}

int main(void){
int mynumber;
printf(&quot;\n Enter a number:&quot;
scanf(&quot;%d&quot;, mynumber);
printf(&quot;\n Result is: %d&quot;, x-squared(mynumber));
}
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |