C语言求数组a[1,2,3,4,5,6,7,8,9,10]中偶数和奇数分别相加求和

匿名网友 |浏览663次
收藏|2020/06/16 13:03

满意回答

2020/06/16 13:36

对数组a[1,2,3,4,5,6,7,8,9,10]中偶数和奇数分别相加求和程序如下:#include<stdio.h>intmain(){inta[10]={1,2,3,4,5,6,7,8,9,10};inti,s1=0,s2=0;for(i=0;i<10;i++)if(a[i]%2==0)s1+=a[i];elses2+=a[i];printf("Evensum:s1=%d\nOddsum:s2=%d\n",s1,s2);return0;}程序的运行结果:

匿名网友

其他回答(1)
  • #include <stdio.h>int main( ){ int a[10]={1,2,3,4,5,6,7,8,9,10}; int i,s1=0,s2=0; for(i=0;i<10;i++) if(a[i]%2==0) s1+=a[i]; else s2+=a[i]; printf("Even sum:s1=%d\nOdd sum:s2=%d\n",s1,s2); return 0;}
    回答于 2020/06/16 13:47
0人关注该问题
+1

 加载中...