c 程序计算五个数字的平方根。变量 count 存储读取的数字的计数。当count小于或等于5时,goto read语句将控制指向读取的标签。否则,程序打印一条消息并停止。
它在正常的程序执行顺序之后使用,将控制权转移到程序的其他部分。

以下是使用 goto 语句的 C 程序 -
#include <math.h>
main(){
double x, y;
int count;
count = 1;
printf("Enter FIVE real values in a LINE </p><p>");
read:
scanf("%lf", &x);
printf("</p><p>");
if (x < 0)
printf("Value - %d is negative</p><p>",count);
else{
y = sqrt(x);
printf("%lf\t %lf</p><p>", x, y);
}
count = count + 1;
if (count <= 5)
goto read;
printf("</p><p>End of computation");
}当执行上述程序时,会产生以下结果 -
Enter FIVE real values in a LINE 2.3 -4.5 2 6.8 -44.7 2.300000 1.516575 Value - 2 is negative 2.000000 1.414214 6.800000 2.607681 Value - 5 is negative End of computation
以上就是C程序解释goto语句的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号