Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int n, i, sum, task, x, y, fact;
- float previous, current, sum_t = 0, t;
- int sum3(int x, int y)
- {
- sum = 0;
- for (i = x; i <= y; i++)
- {
- if (i % 2 == 0)
- sum += pow(i, 3);
- }
- return sum;
- }
- int factorial(int n)
- {
- fact = 1;
- for (i = 1; i <= n; i++)
- fact *= i;
- if (fact == n)
- {
- printf("YES - %d!\n", i);
- return 0;
- }
- return 0;
- }
- double last(float x, int n)
- {
- return powf(-1, n)*(n - 1)*powf(x, n)/(n + 1);
- }
- int main(void)
- {
- printf("Choose the task: 1, 2 or 3:\n");
- scanf("%d", &task);
- if (task == 1)
- {
- printf("Enter the range [x,y]:\n");
- scanf("%d%d", &x, &y);
- printf("%d", sum3(x, y));
- }
- else if (task == 2)
- {
- printf("Enter the number N:\n");
- scanf("%d", &n);
- factorial(n);
- }
- else if (task == 3)
- {
- float x;
- printf("Enter the number x (|x| < 1):\n");
- scanf("%f", &x);
- t = 1;
- current = last(x, t);
- sum_t += current;
- //printf("%f %f\n", current, sum_t);
- t++;
- do
- {
- previous = current;
- current = last(x, t);
- sum_t += current;
- //printf("%f %f %f\n", previous, current, sum_t);
- t++;
- } while (fabs(current - previous) > pow(10, -4));
- printf("%f\n", sum_t);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement