不知道你用的是什么编程语言,大致如下可用(语法按编程语言规范酌情更改):
x:=0;
for i:=0;i++
x:=x+i;
while i<101;
return x;
--------------
x:=0;
i:=1;
do
x:=x+i;
i:=i+1
while i<102;
return x;
#include <stdio.h>
int main()
{
int sum,i;
for(sum=0,i=1;i<101;++i)
sum+=i;
printf("%d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
int sum=0,i=1;
while(i<101)
sum+=i++;
printf("%d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
int sum=0,i=1;
do{
sum+=i;
}while(++i<101);
printf("%d\n",sum);
return 0;
}
本回答被网友采纳用for、while和do...while三种语句求1+2+3+...+100之和?
不知道你用的是什么编程语言,大致如下可用(语法按编程语言规范酌情更改):x:=0;for i:=0;i++ x:=x+i;while i<101;return x;---x:=0;i:=1;do x:=x+i;i:=i+1while i<102;return x;
...while, do while 和for 循环计算1+2+……+100的和。
for(i=1;i<=100;i++){ sum+=i;} \/\/用do while int i=1,sum=0;do { sum+=i;}while(i<=100);
分别用 while, do while 和for 循环计算1+2+……+100的和,C语言编程
while(i<=100){ sum+=i;i++;} printf("%d",sum);} do...while语句: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("%...
C#中;如何用do、while、for语句求1到100的和?
}while(i<=100)\/\/do while(p)\/\/先执行循环体语句,再判断p真假,真执行循环,假退出
c语言 分别用while语句、do~while语句及for语句求1+2+3...+100
include <stdio.h> void main(){ int i =0;int sum =0;\/* While while(i<100){ sum += i;i++;} \/ \/* do while do{ sum += i;i++;}while(i<100);\/ \/* for for(i=0;i<100;i++)sum+=i;\/ printf("%d \\r\\n", sum);} ...
分别利用for语句、while语句以及do while语句编写一个求和程序(即sum=...
回答:int sum=0;for(int i=1;i<n;i++){sum+=i;}int i=1while(i<n){sum+=i;i++;}do{sum+=i;}while(i++<n);System.out.print(sum);
编程求累加和1+2+3+4+5+……+100的奇数和以及偶数和。
= %d\\n",odd, eve); i = 1, odd = 0, eve = 0; do { if (i & 1) odd += i++; else eve += i++; } while(i <= 100); printf("奇数和 = %d, 偶数和 = %d\\n",odd, eve);} ...
用while循环语句求出1+2+3...+100的和
Sub aaa()i = 0 While i < 101 a = a + i i = i + 1 Wend Debug.Print a End Sub Sub bbb()i = 0 Do While i < 101 a = a + i i = i + 1 Loop Debug.Print a End Sub Sub ccc()For i = 1 To 100 a = a + i Next Debug.Print a End Sub ...
2、分别用三种循环语句(while语句、do-while语句、for语句),实现求1...
int sum = 0;int i=0;while(i<100){ sum += (i+1);i++;} printf("%d" , sum);i=0;do { sum += (i+1);i++;}while(i <=100)printf("%d" , sum);for(i = 1 ; i <=100 ; i++){ sum += i;} printf("%d" , sum);
分别用for ,while ,do while 语句编程计算1-100之间奇数和
if(i%2)sum+=i;printf("%d\\n",sum);} include "stdio.h"void main(){ int i=1,sum=0;while(i<=100){ if(i%2)sum+=i;i++;} printf("%d\\n",sum);} include "stdio.h"void main(){ int i=1,sum=0;do { if(i%2)sum+=i;i++;}while(i<=100);printf("%d\\n"...