您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

C程序解释goto语句

2024/5/16 9:05:58发布4次查看
c 程序计算五个数字的平方根。变量 count 存储读取的数字的计数。当count小于或等于5时,goto read语句将控制指向读取的标签。否则,程序打印一条消息并停止。
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语句的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录