c語(yǔ)言用while和dowhile分別編寫(xiě)一個(gè)求和程序?
while求和代碼
#include <stdio.h> int main() { int i = 0, sum = 0, n; scanf ("%d", &n); while (i <= n){ sum += i; i++; } printf ("%d ", sum); }
do---while求和代碼
#include <stdio.h> int main() { int i = 0, sum = 0, n; scanf ("%d", &n); do{ sum += i; i++; }while (i <= n); printf ("%d ", sum); }