How to store calculation results in a field

Field names B, C, and D exist in collection name A.
B and C are integers.
The value of D is the sum of B and C.
I want to know.

  1. How to achieve it with API.
  2. How to achieve it with GUI.
    …And I want a sample of the APIs.
    Documents containing {collectionName} are difficult to execute.

Thanks in advance.

  1. Method 1: Define D using a formula field where D = B + C.
  2. Method 2: Use a workflow to calculate B+C and update the value of D.
  3. What do you mean by using the API? The API can update D, but it doesn’t automatically calculate B+C.