1. do...while循环:
#include <stdio.h> int main() { int i = 1; int sum = 0; do{ sum+=i; i++; }while(i<=100); printf("%d\n",sum); }
2. while循环:
#include <stdio.h> int main() { int i = 1; int sum = 0; while(i<=100) { sum+=i; i++; } printf("%d\n",sum); }
3.for循环:
#include <stdio.h> int main() { int i,sum; for(i = 1,sum = 0; i<=100; i++) { sum+=i; } printf("%d\n",sum); }
例子输出结果: