weixin_44884017
weixin_44884017
2019-10-05 23:30

编写了一个程序,没有报错但是不能正常运行,请各位前辈帮忙看看

  • c++
  • c语言
  • 开发语言

#include
#include
#include

struct Data /*定义结构体,每组包含元素名称和电负性两个信息*/
{
char cElement[3]; /*元素名*/
double fElectronegativity; /*电负性*/
}data[]={{"H",7.18},{"Li",3.01},{"Be",4.9},{"B",4.29},{"C",6.27},
{"N",7.30},{"O",7.54},{"F",10.41},{"Na",2.85},{"Mg",3.75},
{"Al",3.23},{"Si",4.77},{"P",5.62},{"S",6.22},{"Cl",8.30},
{"K",2.42},{"Ca",2.2},{"Sc",3.34},{"Ti",3.45},{"V",3.6},
{"Cr",3.72},{"Mn",3.72},{"Fe",4.06},{"Co",4.3},{"Ni",4.40},
{"Cu",4.48},{"Zn",4.45},{"Ga",3.2},{"Ge",4.6},{"As",5.3},
{"Se",5.89},{"Br",7.59},{"Rb",2.34},{"Sr",2.0},{"Y",3.19},
{"Zr",3.64},{"Nb",4.0},{"Mo",3.9},{"Ru",4.5},{"Rh",4.30},
{"Pd",4.45},{"Ag",4.44},{"Cd",4.33},{"In",3.1},{"Sn",4.30},
{"Sb",4.85},{"Te",5.49},{"I",6.76},{"Cs",2.18},{"Ba",2.4},
{"La",3.1},{"Hf",3.8},{"Ta",4.11},{"W",4.40},{"Re",4.02},
{"Os",4.9},{"Ir",5.4},{"Pt",5.6},{"Au",5.77},{"Hg",4.91},
{"Tl",3.2},{"Pb",3.90},{"Bi",4.69},{"CW",4.69}}; /*CW 表示错误*/

int main()
{
int n; /*n为第几个元素,g为元素个数,sum为开根数*/
int i;float g; /*i为数组循环*/
long double product,result,sum,Eg; /*product为乘积,result为结果*/
char c; /*c为输入元素名/

printf("-------------------------欢迎使用本程序------------------------\n");
printf("--------------本程序可用于计算半导体导带及价带位置-------------\n");
printf("-----------------通过给出带隙宽度及分子式即可计算--------------\n");
printf("------注意:本程序不能识别大小写,请输入元素时务必正确输入-----\n");
printf("------------如铁元素请输入Fe,元素个数输入阿拉伯数字-----------\n");
printf("--------------------输入完成请输入end或End---------------------\n");      /*引言部分*/
printf("---------------------------------------------------------------\n\n\n");
printf("------------------------请输入带隙宽度-------------------------\n");
scanf("%lf",&Eg);


n=1;result=1;
sum=0;

while(1)
{
    printf("请输入第%d个元素\n",n);
    scanf("%s",&c);
    i=0;

    while(strcmp(data[i].cElement,c)!=0&&strcmp(data[i].cElement,"CW")!=0&&strcmp(data[i].cElement,"end")!=0&&strcmp(data[i].cElement,"End")!=0)
    {
        i++;
    }
    if(strcmp(data[i].cElement,"end")!=0||strcmp(data[i].cElement,"End")!=0)
    {
        break;
    }
    else if(strcmp(data[i].cElement,"CW")!=0)
    {
        printf("请检查您输入的元素是否正确");
    }
    else
    {
        printf("请输入第%d个元素在分子式中的个数\n",n);
        scanf("%f",&g);
        product=pow(data[i].fElectronegativity,g);
        result=result*product;
        sum=sum+g;
    }


    n++;
}
result=pow(result,1/sum);
printf("ECB=%fl.2",result-4.5-Eg/2);
printf("EVB=%fl.2",result-4.5+Eg/2);

getchar();
return 0;

}

输入2.2 Fe后跳出图片所示内容
小弟是自学编程,请各位前辈老师不吝赐教,谢谢您的帮助!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答