此程序有一个错误:删掉getch( )或改为putchar(定义参数) 本人编了一个用goto实现此程序的功能: #include<stdio.h> void main() { int n,i; loop: printf("please input a number:"); scanf("%d",&n); if (n<=2) { printf("This is number is fault,Please input another number:"); scanf("%d",&n); } for(i=2; i<n;i++) if (n%i==0) break; if(i<n) printf("%d not sushu \n",n); else printf("%d is sushu \n",n); goto loop; }
两种都能实现此功能,不过还是用while循环语句更好. ok!!! 浅谈谈本人的想法.
#include<stdio.h> void main() { int n,i; printf("please input a number:");
t scanf("%d",&n); if(n<=2) {printf("This is number is fault,Please input another number:"); goto to; } for(i=2; i<n;i++) if (n%i==0) break; if(i<n) printf("%d not sushu \n",n); else printf("%d is sushu \n",n); getch(); }
这一个用了GOTO。看看;