Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<math.h>
- void flashStandarInput(void)
- {
- int IntCharacter;
- while ((IntCharacter = getchar()) != '\n' && (IntCharacter != EOF));
- }
- double fakutaet(unsigned int n)
- {
- if (n <= 1)
- return 1;
- else
- return n*fakutaet(n - 1);
- }
- double berechnen1(double x)
- {
- unsigned int lv;
- double x_2 = x;
- double ergebnis = 1;
- for (lv = 1; lv < 10; lv++)
- {
- ergebnis = ergebnis + ( x_2 / fakutaet(lv));
- x_2 = x_2*x;
- }
- return ergebnis;
- }
- double berechnen2(double x)
- {
- unsigned int lv;
- double x_2 = x;
- double ergebnis = 1;
- for (lv = 1; (x_2/fakutaet(lv))>0.0001; lv++)
- {
- ergebnis = ergebnis + (x_2 / fakutaet(lv));
- x_2 = x_2*x;
- }
- return ergebnis;
- }
- double anzahl(double x)
- {
- unsigned int lv;
- double anzahl=1;
- double x_2 = x;
- double ergebnis = 1;
- anzahl = 0;
- for (lv = 1; (x_2 / fakutaet(lv))>0.0001; lv++)
- {
- ergebnis = ergebnis + (x_2 / fakutaet(lv));
- x_2 = x_2*x;
- anzahl++;
- }
- return anzahl;
- }
- int main(void)
- {
- double x;
- do {
- double ergebnis_math;
- double abweichung;
- printf("Geben Sie bitte eine Zahl, deren Exponential berechnen soll!\t");
- scanf("%lf", &x);
- flashStandarInput();
- printf("\nDie Interation nach 10 Summanden ist \t\t\t\t%lf\n", berechnen1(x));
- ergebnis_math = exp(x);
- abweichung = ((ergebnis_math - berechnen1(x)) / ergebnis_math) * 100;
- printf("\nDas richtiges Ergebnis mit exp(x) ist \t\t\t\t%lf\n", ergebnis_math);
- printf("\nDie Abweichung ist \t\t\t\t\t\t%lf%%\n", abweichung);
- printf("\nDas Ergebnis, bis ein Suman nicht weiter %cndert:\t\t%lf\n", 132, berechnen2(x));
- printf("\nDie Anzahl der Summanden ist \t\t\t\t\t%.0lf\n\n\n\n", anzahl(x));
- }while (x !=0 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement