2025-03-06 22:45:14 +08:00

21 lines
426 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
编程求100以内的所有奇数之和以及偶数之和。使用for循环
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,odd,even;
odd=even=0;
/**********Program**********/
for(i=1;i<=100;i++){
if(i%2){
odd+=i;
}else{
even+=i;
}
}
/********** End **********/
printf("奇数之和为:%d,偶数之和为:%d\n",odd,even);
}