for语句:
#include <stdio.h> int main(void) { int i,sum=0; for(i=0;i<=100;i++) { sum = sum+i; } printf("the sum is %d\n",sum); return 0; }
while语句:
#include<stdio.h> main() { int i=0,sum=0; while(i<=100) { sum = sum+i; i++; } printf("the sum is %d\n",sum); return 0; }
do-while语句:
#include<stdio.h> main() { int i,sum=0; do { sum = sum+i; i++; } while(i<=100); printf("the sum is %d\n",sum); return 0; }
goto语句:
#include<stdio.h> main() { int i=0,sum=0; loop: if(i<=100) { sum = sum + i; i++; goto loop; } printf("the sum is %d\n",sum); return 0; }
以上都是linux下经gcc编译通过的程序,确认无误!