goto 语句它在正常的程序执行顺序之后使用,将控制权转移到程序的其他部分。
程序以下是使用 goto 语句的 c 程序 -
#include <math.h>main(){ double x, y; int count; count = 1; printf("enter five real values in a line
"); read: scanf("%lf", &x); printf("
"); if (x < 0) printf("value - %d is negative
",count); else{ y = sqrt(x); printf("%lf\t %lf
", x, y); } count = count + 1; if (count <= 5) goto read; printf("
end of computation");}
输出当执行上述程序时,会产生以下结果 -
enter five real values in a line2.3 -4.5 2 6.8 -44.72.300000 1.516575value - 2 is negative2.000000 1.4142146.800000 2.607681value - 5 is negativeend of computation
以上就是c程序解释goto语句的详细内容。
