Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <math.h>
  6.  
  7.  
  8.  
  9. long ReadNummer();
  10. long FaktorierNum(long x);
  11. double Taylorsin(double x, long n);
  12. double Faktorielle(long x);
  13.  
  14.  
  15. int main()
  16.  
  17. {
  18.  
  19.     long nummer, ordnung, i;
  20.     double argument;
  21.  
  22.     nummer = ReadNummer();
  23.  
  24.     printf("eingelesene zahl: %ld = ", nummer);
  25.  
  26.     FaktorierNum(nummer); //nummer faktorieren in funktion.
  27.  
  28.     printf("Geben sie argument fuer sinustaylor-entwicklung ein: ");
  29.     scanf("%lf", &argument);
  30.     getchar();
  31.     printf("zur ordnung: ");
  32.     scanf("%ld", &ordnung);
  33.     getchar();
  34.  
  35.     printf("sin( %lf ) nach taylorentwicklung zur ordnung %ld = %lf \n", argument, ordnung, Taylorsin(argument, ordnung)); //ausgabe ergebnis
  36.  
  37.     printf("taylorentwicklung von %lf : \n", argument);
  38.  
  39.     for(i = 2; i <= 7; i++) {
  40.  
  41.         printf("zur ordnung %ld = %lf   diferenz zum sin = %lf \n", i, Taylorsin(argument, i), fabs(Taylorsin(argument, i) - sin(argument)));
  42.  
  43.     }
  44.  
  45.  
  46.     return 0;
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53. long ReadNummer() {
  54.     long x;
  55.  
  56.     printf("Gebe positive Ganzzahl ein: ");
  57.     scanf("%ld", &x);
  58.     getchar();
  59.     return x;
  60. }   //end ReadNummer
  61.  
  62.  
  63. long FaktorierNum(long x) {
  64.     long i;
  65.  
  66.     if(x < 0) {
  67.         printf("Bitte positive ganzzahl eingeben!");
  68.         return 0;
  69.     }
  70.     for(i = 2; i <= x; ) {
  71.  
  72.         if((x % i) == 0) {
  73.             if(x == i) {
  74.                   printf("%ld\n", i);
  75.                   i++;
  76.             } else {
  77.             printf("%ld * ", i);
  78.             x /= i;
  79.             }
  80.         } else {
  81.             i++;
  82.         }
  83.  
  84.     }
  85.     return 1;
  86. } //end FaktorierNum
  87.  
  88.  
  89. double Taylorsin(double x, long n) {
  90.     long i;
  91.     double erg = 0.0;
  92.  
  93.     for(i = 0; i <= n; i++) {
  94.         erg = pow(-1, i) * pow( x, 2 * i + 1) / Faktorielle( 2 * i + 1);
  95.     }
  96.     return erg;
  97.  
  98. }//end Taylorsin
  99.  
  100.  
  101. double Faktorielle(long x) {
  102.  
  103.     long i;
  104.     double erg = 1.0;
  105.  
  106.     for(i = 2; i <= x; i++) {
  107.         erg = erg * i;
  108.     }
  109.  
  110.     return erg;
  111.  
  112. } //end Faktorielle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement