hhjc.net
当前位置:首页 >> whilE循环语句1加到100 >>

whilE循环语句1加到100

int i=1,sum=0; while(i sum+=i; i++; }

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

#include<stdio.h> int main() { int i=1,sum=0; while(i++<=100) { sum+=i; } printf("sum=%d\n",sum); return 0; }

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

package com.kk.print;/** 分别使用循环语句for、while、repeat实现求从1加到100的和 */ public class ForWhiledoWhile { public static void main(String[] args) { int result1 = 0; int result2 = 0; int result3 = 0; for (int i = 0; i <= 100; i++) { result1 += i; } int

var i=1;<br>var sum=0;<br>while(i<=100){<br>i++;<br>sum = sum + i;<br>}<br>alert(sum);<br><br>没测试,不知有无错误,有错请追问.

int sum=0,i; for(i=1;i sum+=i; sum=0; while(i { sum+=i; i+=2; } sum=0; i=1; do { sum+=i; i+=2; }while(i

int main() { int i = 100,num = 0; while(i) { num = num + i; i--; } printf("%属d\n",num); return 0; }

while(i { sum=sum+i; i=i+1; } 这样就没逻辑错误了,1加到100,应该是1+2+3+4+.100,而不是2+3+4+5+101

方法1:笨办法int i = 0;int sum = 0;while i 评论0 0 0

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