Bài 19: Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!

Bài 19: Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!

Bài tập 19 (Dạng bài tập này giúp các bạn giỏi về: Lưu đồ thuật toán)

Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!

Cài đặt

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int i, n;
    float x, S, T;
    long M, N;
    printf("\nNhap x: ");
    scanf("%f", &x);
    do
    {
    printf("\nNhap n(n >= 1) : ");
    scanf("%d", &n);
      if(n < 1)
      {
          printf("\n N phai >= 1. Xin nhap lai !");
      }

    }while(n < 1);

    S = 1 + x;
    N = 1;
    i = 1;

    while(i <= n)
    {
        T = pow(x, (2 * i + 1));
M = i * 2 + 1;
N = N * M * (M - 1);
S = S + T/N;
i++;
    }
    printf("\nTong la %f", S);
    getch();
    return 0;
}

Cách khác

int main()
{
    int n, x, i, j;
    unsigned long t1, t2;
    float S;
    i = 1;
    j = 1;
    S = 1;
    cout << "Enter x, n: ";
    cin >> x >> n;
    t1 = x;
    t2 = 1;
    while (i <= n+1)
    {
        S = S + (float) t1 / t2;
        t1 = t1 * x * x;
        j = i * 2;
        t2 = t2 * j * (j + 1);
        i++;
    }
    cout << "S = " << S;

    // END MAIN
    system("pause");
}
Bạn thấy bài viết này như thế nào?: 
Average: 8.9 (124 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Đừng bỏ lỡ sự kiện SALE & MARKETING chất nhất 2019

Đừng bỏ lỡ sự kiện SALE & MARKETING chất nhất 2019

Cung cấp giải pháp tăng trưởng x10, x100... từ thực tế của các doanh nghiệp như Tiki, Gamota, Coffe House. Cách tối ưu sale và trải nghiệm khách hàng trên mobile.

Drupal modules weights - để quản lý and execution order

Drupal modules weights - để quản lý and execution order

One of the good features that Drupal offers to the developer is the module execution order. Out of the box, Drupal has a mechanism to allow it to execute module's hooks in predefined order based on modules weight (order).

Hướng dẫn custom entity reference: Drupal & Entity reference

Hướng dẫn custom entity reference: Drupal & Entity reference

There are some good examples out there on how to create a custom Entity reference Behaviour plugin, but not so much for Selection handlers.

Công ty diệt chuột T&C

 

Diet con trung