Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<stdio.h>
  3. #include<math.h>
  4.  
  5. void flashStandarInput(void)
  6. {
  7. int IntCharacter;
  8. while ((IntCharacter = getchar()) != '\n' && (IntCharacter != EOF));
  9. }
  10. double fakutaet(unsigned int n)
  11. {
  12. if (n <= 1)
  13. return 1;
  14. else
  15. return n*fakutaet(n - 1);
  16. }
  17.  
  18. double berechnen1(double x)
  19. {
  20. unsigned int lv;
  21. double x_2 = x;
  22. double ergebnis = 1;
  23. for (lv = 1; lv < 10; lv++)
  24. {
  25. ergebnis = ergebnis + ( x_2 / fakutaet(lv));
  26. x_2 = x_2*x;
  27. }
  28. return ergebnis;
  29. }
  30. double berechnen2(double x)
  31. {
  32. unsigned int lv;
  33. double x_2 = x;
  34. double ergebnis = 1;
  35. for (lv = 1; (x_2/fakutaet(lv))>0.0001; lv++)
  36. {
  37. ergebnis = ergebnis + (x_2 / fakutaet(lv));
  38. x_2 = x_2*x;
  39. }
  40. return ergebnis;
  41. }
  42. double anzahl(double x)
  43. {
  44. unsigned int lv;
  45. double anzahl=1;
  46. double x_2 = x;
  47. double ergebnis = 1;
  48. anzahl = 0;
  49. for (lv = 1; (x_2 / fakutaet(lv))>0.0001; lv++)
  50. {
  51. ergebnis = ergebnis + (x_2 / fakutaet(lv));
  52. x_2 = x_2*x;
  53. anzahl++;
  54. }
  55. return anzahl;
  56. }
  57. int main(void)
  58. {
  59. double x;
  60. do {
  61. double ergebnis_math;
  62. double abweichung;
  63. printf("Geben Sie bitte eine Zahl, deren Exponential berechnen soll!\t");
  64. scanf("%lf", &x);
  65. flashStandarInput();
  66.  
  67. printf("\nDie Interation nach 10 Summanden ist \t\t\t\t%lf\n", berechnen1(x));
  68. ergebnis_math = exp(x);
  69. abweichung = ((ergebnis_math - berechnen1(x)) / ergebnis_math) * 100;
  70. printf("\nDas richtiges Ergebnis mit exp(x) ist \t\t\t\t%lf\n", ergebnis_math);
  71. printf("\nDie Abweichung ist \t\t\t\t\t\t%lf%%\n", abweichung);
  72. printf("\nDas Ergebnis, bis ein Suman nicht weiter %cndert:\t\t%lf\n", 132, berechnen2(x));
  73. printf("\nDie Anzahl der Summanden ist \t\t\t\t\t%.0lf\n\n\n\n", anzahl(x));
  74. }while (x !=0 );
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement