-->
当前位置:首页 > ELSE > 正文内容

C语言 goto

Luz3年前 (2021-06-20)ELSE4439

goto语句允许把控制无条件转移到同一函数内的被标记的语句。一般不用在正式代码的编写中。最近同学给了张流程图让我转成代码,发现用goto能方便很多。

标号

image.png标号前

image.png

标号后

改写

流程图一个框做成一个label,框与框之间的跳转就可以用goto了


代码后的效果:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
 	double _M=251234.0;
    double _b=300.0;
    double _fc=14.3;
    double _fy_=360.0;
    double _fy=360.0;
    double _as=444.0;
    double _as_=333.0;
    double _x1=1.0;

    double _xsmax=0.466;
    double _eb=0.518;
    double _Pmin=0.002;
    double _As=0.0;
    double _As_=0.0;
    double _h=600.0;            
    double x;
    //int a=1;

	//double _M=0;
	double _e=0,x2=0,_xs,_x;
	aa_1:
	double _h0=_h-_as;
    goto aa_2;
    
    aa_3:
    if(_As_>_M)
        goto aa_4;
    else
        goto aa_13;
        
    aa_4:
    x=_eb*_h0;
    goto aa_5;
        
    aa_2:
    _xs=_M/(_x1*_fc*_b*_h0*_h0);
    //printf("%lf ",_xs);
    if(_xs<_xsmax)
    	goto aa_3;
    else
		goto aa_14;
    aa_14:
    printf("123");
    return 0;
    aa_5:
    _As_=((_M-_x1*_fc*_b*_h0*_h0*_eb*(1-0.5*_eb))/(_fy_*(_h0-_as_)));
    if(_As_>=(_Pmin*_b*_h0))
        goto aa_6;
    else
        goto aa_13;
        
    aa_13:
    _As_=_Pmin*_b*_h0;
    goto aa_12;
    aa_6:
    _As=_As_+_eb*((_x1*_fc*_b*_h0)/_fy);
    goto aa_7;
    aa_7:
    printf("As:%lf,As':%lf",_As,_As_);
    return 0;

    aa_12:
    _xs=(_M-_fy_*(_As_*(_h0-_as_)))/(_x1*_fc*_b*_h0*_h0);
    goto aa_11;
    
    aa_11:
    _e=1-sqrt((1-x2*_xs));
    if(_e<_eb)
        goto aa_10;
    else
        goto aa_5;
    aa_10:
    x=_e*_h0;
    if(x>=(2*_as_))
        goto aa_8;
    else
        goto aa_9;
    
    aa_9:
    _As=_M/(_fy*(_h0-_as));
    goto aa_7;
    
    aa_8:
    _As=_As_+((_x1*_fc*_b*_x)/_fy);
    goto aa_7;
}


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。