望采纳!
#include
void main() {
int i,n;
int result1=0,result2=0;
printf("请输入n:");
scanf("%d",&n);
for(i=0; i<=n; i++) {
if(i%2 == 0)
result1 += i;
else
result2 += i;
}
printf("偶数和为:%d\n",result1);
printf("奇数和为:%d\n",result2);
}
#include
int main(){
int n;
scanf("%d",&n);
printf("奇数和为:%d\n",n*n);
printf("偶数和为:%d\n",n*n+n);
return 0;
}
# include
void main()
{
int i, n, sum1 = 0, sum2 = 0;
printf("请输入一个正整数:");
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
if(i % 2 == 1)
sum1 += i;
else
sum2 += i;
}
printf("1到%d之间的奇数和为:%d\n", n, sum1);
printf("1到%d之间的偶数和为:%d\n", n, sum2);
}
望采纳