Created
February 9, 2020 21:52
-
-
Save Zeko369/532d9309a9eb2f8cf60217eef636c29f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
double red(double x) | |
{ | |
int plus = 0; | |
int i = 1; | |
double sum = 1; | |
double last = 0; | |
double fact = 1; | |
double pot = x; | |
do | |
{ | |
last = sum; | |
pot *= x; | |
fact *= i; | |
if (plus) | |
{ | |
sum += pot / fact; | |
} | |
else | |
{ | |
sum -= pot / fact; | |
} | |
i++; | |
plus = !plus; | |
} while (last != sum); | |
printf("Broj iteracija: %d\n", i); | |
return sum; | |
} | |
int main() | |
{ | |
double sum = red(4); | |
printf("%lf", sum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment