C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了S.E.M.F.物理C代码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
需要一些帮助来解决这个程序的一个小问题.我创建了s.E.m.F.在物理学C计算公式一切都很好,但我的B.E.含有a5的配方.

它说错误:标识符“a5”是未定义的,我知道这意味着什么,但如果我输入偶数甚至奇数或奇数奇怪的A Z值,我将如何从选择语句中获取a5.

#include <iostream>
#include <cstdlib>
#include <math.h>

using namespace std;

int main()
{
    int a,Z;

    // Main body of Semi-Empirical Mass Formula
    cout <<"Enter the mass number A: ";
    cin >> A;
    cout <<"\n";
    cout <<"Enter the atomic number Z: ";
    cin >> Z;
    cout <<"\n";

    // Constants from formula,units in MeV(millions of electron volts)
    double a1 = 15.67;          
    double a2 = 17.23;
    double a3 = 0.75;
    double a4 = 93.2;

    if(Z % 2 == 0 && (A - z) % 2 == 0)

        double a5 = 12.0;

    else if(Z % 2 != 0 && (A - z) % 2 != 0)

        double a5 = -12.0;

    else

        double a5 = 0;


    // Formula for to compute the binding energy
    double B =a1 * A - a2 * pow( A,2/3) - a3 * (pow(Z,2) / pow(A,1/3)) - a4 * (pow(A - 2 * Z,2) / A) + (a5 / pow(A,1/2));

    // Formula for to compute the binding energy per nucLeon
    double B_E = B / A;


    return 0;

}

解决方法

把定义

double a5 = 0.0;

在a4定义的正下方,并在每个ifs案例中使用它.

大佬总结

以上是大佬教程为你收集整理的S.E.M.F.物理C代码全部内容,希望文章能够帮你解决S.E.M.F.物理C代码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。