C goto

http://c.biancheng.net/view/266.html

当程序遇到 goto 后, 会无条件跳转到标签后出,然后程序按照顺序执行

例子:

#include <stdio.h>
#include <math.h>

int main(int argc, const char *argv[])
{
    float a, b, c;
tip:
    printf("a = ");
    scanf("%f",&a);
    printf("b = ");
    scanf("%f",&b);
    printf("c = ");
    scanf("%f",&c);
    if(a+b<=c || a+c<=b || b+c<=a)
    {
        printf("input error\n");
        goto tip;
    }
    float s = 0;
    s = (a+b+c) / 2;
    float area = 0;
    area = sqrt(s*(s-a)*(s-b)*(s-c));
    printf("area = %f\n",area);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/electronic/p/10776374.html