Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- long ReadNummer();
- long FaktorierNum(long x);
- double Taylorsin(double x, long n);
- double Faktorielle(long x);
- int main()
- {
- long nummer, ordnung, i;
- double argument;
- nummer = ReadNummer();
- printf("eingelesene zahl: %ld = ", nummer);
- FaktorierNum(nummer); //nummer faktorieren in funktion.
- printf("Geben sie argument fuer sinustaylor-entwicklung ein: ");
- scanf("%lf", &argument);
- getchar();
- printf("zur ordnung: ");
- scanf("%ld", &ordnung);
- getchar();
- printf("sin( %lf ) nach taylorentwicklung zur ordnung %ld = %lf \n", argument, ordnung, Taylorsin(argument, ordnung)); //ausgabe ergebnis
- printf("taylorentwicklung von %lf : \n", argument);
- for(i = 2; i <= 7; i++) {
- printf("zur ordnung %ld = %lf diferenz zum sin = %lf \n", i, Taylorsin(argument, i), fabs(Taylorsin(argument, i) - sin(argument)));
- }
- return 0;
- }
- long ReadNummer() {
- long x;
- printf("Gebe positive Ganzzahl ein: ");
- scanf("%ld", &x);
- getchar();
- return x;
- } //end ReadNummer
- long FaktorierNum(long x) {
- long i;
- if(x < 0) {
- printf("Bitte positive ganzzahl eingeben!");
- return 0;
- }
- for(i = 2; i <= x; ) {
- if((x % i) == 0) {
- if(x == i) {
- printf("%ld\n", i);
- i++;
- } else {
- printf("%ld * ", i);
- x /= i;
- }
- } else {
- i++;
- }
- }
- return 1;
- } //end FaktorierNum
- double Taylorsin(double x, long n) {
- long i;
- double erg = 0.0;
- for(i = 0; i <= n; i++) {
- erg = pow(-1, i) * pow( x, 2 * i + 1) / Faktorielle( 2 * i + 1);
- }
- return erg;
- }//end Taylorsin
- double Faktorielle(long x) {
- long i;
- double erg = 1.0;
- for(i = 2; i <= x; i++) {
- erg = erg * i;
- }
- return erg;
- } //end Faktorielle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement