求20-350内所有偶数或奇数的和,用C语言写
发布网友
发布时间:2023-10-09 16:38
我来回答
共3个回答
热心网友
时间:2023-10-11 19:41
#include "stdio.h"
void main()
{
int i,j,sum1=0,sum2=0;
for(i=20;i<=350;i+=2)
sum1=sum1+i;
printf("偶数的和是%d\n",sum1);
for(j=21;j<=350;j+=2)
sum2=sum2+j;
printf("偶数的和是%d",sum2);
}
热心网友
时间:2023-10-11 19:42
main(){
int i,total1,total1;
total1 = 0;
total2 = 0;
for(i=20;i<=350;i++){
if(i % 2 == 0)
total1 += i;
else
total2 += i;
}
printf("偶数的和:%d\n", total1);
printf("奇数的和:%d\n", total2);
}
热心网友
时间:2023-10-11 19:42
#include<stdio.h>
void main()
{ int i;sum1=0;sum2=0;
for(i=20;i<=350;i++)
if(i%2==0)
sum1=sum1+i;
else
sum2=sum2+i;
printf("sum1=%d,sum2=%d\n",sum1,sum2);
}