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

博客 1浏览

对数组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;}程序的运行结果:

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