编写程序,求1-100之间的奇数和偶数之和,并加以输出。

2024-11-22 20:23:53
推荐回答(4个)
回答1:

#include
main()
{
int s1,s2,i;
s1=s2=0;
for(i=1;i<=100;i++)
if(i%2==0) s1+=i;else s2+=i;
printf("偶数和是:%d\n奇数和是:%d\n",s1,s2)
}

回答2:

#include
void main()
{
int s1,s2, i=1,j=2;
int sum1=sum2=0;
while(i<100)
{
sum1+=i;
i=i+2;
}
while(j<=100)
{
sum2+=j;
j=j+2;
}
cout<<"奇数:"<cout<<"偶数:"<}

回答3:

VB
?

回答4:

public class qita {

public static void main(String[] args) {
long sum01 = 0;
long sum02 = 0;
for(int i=0;i<=100;i++){
if(i%2 == 0)
sum01 += i;
else sum02 += i;
}

System.out.println("1-100偶数和是" + sum01);
System.out.println("1-100奇数和是" + sum02);
}
}