用oddsum=1+3+5+···+99来计算奇数和;evensum=2+4+6+···+100来计算偶数和。首先设置两个计数器:oddsum,evensum。其初值为0,利用if···else来判断奇偶数,来分别累加到计数器。1,将i的初值置为1;2...
}printf("奇数之和:%d\n偶数之和:%d\n",ji,ou);return0;}
intF1(){return50*(1+99)/2;}intF2(){return50*(2+100)/2;}voidmain(){printf("Oddnumbersum=%d,Evennumbersum=%d\n",F1(),F2());}解法2include<stdio.h>intF1(){inti,...
C语言中编程计算1至100以内的奇数和偶数并分别求和include<stdio.h>voidmain(){inti,sumA=0,sumB=0;for(i=1;i<=100;i++){if(i%2!=0){sumA++;}else{sumB++;}}printf("100以内的奇数和是:...
include<stdio.h>voidmain(){inti=1,s1=0,s2=0;while(i<=100){i%2?s1+=i:s2+=i;i++;}printf("奇数和:%d\n偶数和:%d",s1,s2);}用do-while循环:include<stdio.h>voidmain(){inti=1,s1=...
include<stdio.h>voidmain(){inti;staticintsum1,sum2;for(i=1;i<=100;i++){if((i%2)==0)sum1+=i;elsesum2+=i;}printf("奇数和为:%d偶数和为:%d",sum2,sum1);}...
include<stdio.h>voidmain(){inti,s1=0,s2=0;for(i=1;i<=100;i++)(i%2)?s1+=i:s2+=i;printf("奇数之和:%d\n偶数之和:%d",s1,s2);}已调试。运行结果截图:...
for(inti=1;i<=100;i++){if(i%2==0){a+=i;}else{b+=i;}}printf("100以内的偶数和为:%d\n",a);printf("100以内的奇数和为:%d\n",b);r...
参考代码如下:include<stdio.h>intmain(){inti,s1=0,s2=0,s=0;for(i=1;i<=100;++i){if(i%2==0)s2+=i;elses1+=i;s+=i;}printf("奇数和%d,偶数和%d,总和%d",s1,s2,s);return0;}...
这用人算得了。(1+100)100/2=5050每个偶数比奇数大1所以偶数和比奇数和多100/2所以奇数和为2500偶数和为2550不知道对不对。