#include <stdio.h>
//goto实现循环
void test001()
{
int i,sum=0;
i=1;
loop:
if(i<=100)
{
sum=sum+i;
i++;
goto loop;
}
printf("%d\n",sum);
}
void test002()
{
int i = 1,sum = 0;
if (i == 10)
goto loop;
any:
if (i <= 100)
{
sum += i;
i++;
goto any;
}
//循环执行完成 继续执行下面
loop:
printf("%d\n",sum);
}
int test003()
{
int a=60;
scanf("%d",&a);
if(a>=90)
{
goto score_90;
}else if(a<90 && a>=60)
{
goto score_60;
}else{
goto score_10;
}
score_90:
printf("优秀!\n");
return 0;
score_60:
printf("良好!\n");
return 0;
score_10:
printf("不及格!\n");
return 0;
}
void test004()
{
int a,b,c=0;
loop:
scanf("%d %d",&a,&b);
if(a>b)
{
goto loop1;
}
else{
printf("%d<%d\n",a,b);
goto loop;
}
loop1:
c=b;
b=a;
a=c;
printf("a=%d b=%d\n",a,b);
}
//c语言goto语句的使用
//goto和汇编语句比较像 使用ida动态调试一下
//goto语句也称为无条件转移语句
int main(void){
test001();
test002();
test003();
test004();
return 0;
}
c语言goto语句的使用
最新推荐文章于 2023-07-05 19:58:08 发布