public class Demo05ShiCao{
public static void main(String[] args){
int sum1 = 0;
for(int i = 1; i <= 100; i++){
if(i % 2 == 0){
sum1 +=i;
}
}
System.out.println("结果是:" + sum1);
System.out.println("==============================================");
int sum2 = 0;
int c = 1;
while(c <= 100){
c++;
if(c % 2 == 0){
sum2 += c;
}
}
System.out.println("结果是:"+sum2);
System.out.println("==============================================");
int sum3 = 0;
int d = 1;
do{
if(d % 2 == 0){
//int d;
sum3 += d;
}
d++;
}while(d <= 100);
System.out.println("结果是:"+sum3);
}
}
拿走不谢
#include
main()
{
int i=0,sum=0;
while(i<=100)
{i+=2;
sum+=i;
}
printf("1到100的偶数之和为:%d",sum);
}
wihle的做法
int sum = 0; //当前之和
int i = 1; //加数
while (i<=100){
if (i%2==0){//模0=偶数
sum+=i;//偶数进来后他们相加
}
i++;
}
System.out.println(sum);
楼下的用的是C,楼主需要什么编程语言的啊?
vf的是:
store 0 to i,s
do while i<=100
if mod(i,2)=0
s=s+i
endif
i=i+1
enddo
?s
结果就是2550
public class work13 {
public static void main(String[] args) {
// int sum=0;
// for (int i = 1; i <= 100; i++ ){
// if (i%2==0){
// sum = sum + i;
// }
// }
// System.out.println(sum);
int i = 0;
int sum = 0;
while(i <= 100){
sum = sum + i;
i =i + 2;
}
System.out.println(sum);
}
}