mdsk.net
当前位置:首页 >> Do whilE算1加到100的和 >>

Do whilE算1加到100的和

main() { int i,sum=0; i=1; do { sum=sum+i; i++; } while(i<=100) printf("%d\n",sum); }

把sum+=m;放到for循环里面~

#include main() int a,num; num=0; do { num+=a; a++} while(a

#include <stdio.h> void main() { int i = 1; int sum = 0; do { if (i % 5 != 0) sum += i; } while (++i <= 100); printf("1到100内除去被5整除的以为的所有数之和为:%d\n", sum); } 不懂的地方给我留言

while语句:#include<stdio.h> int i=0,sum=0;main(){while(i<=100){ sum+=i;i++;}printf("%d",sum);}dowhile语句:#include<stdio.h> main(){int i=0,sum=0;do{ sum+=i; i++;}while(i<=100);printf("%d",sum);}for循环:#include<stdio.h> main(){int i,sum=0;for(i=0;i<=100;i++){sum+=i;}printf("%d",sum);}

int i = 1;int sum = 0; do { sum += i++; } while(i 评论0 0 0

Dim Sj As Integer Dim So As Integer Dim i As Integer Sj = 0 So = 0 i = 1 Do While i <= 100 If i Mod 2 = 1 Then Sj = Sj + i Else So = So + i End If i = i + 1 Loop MsgBox "奇数和为:" & Sj MsgBox "偶数和为:" & So

using System; public class MyClass { public static void Main() { int i, sum; i=0; sum=0; while(i

public static void main(string[] args) { int count = 0; int i = 1; while(i count = count + i; i++; } system.out.println(count); } 运行结果:5050

#include<iostream.h> void main() { int i=1,s=0; do{ if(i%2==0){s+=i;} i++; } while(i<=100); cout<<"s="<<s<<endl; }

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com