1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { int j=0,o=0,i; for(i=1;i<=100;i++) { if(i%2==1)j=j+i; else o=o+i; } printf("the sum of odd numbers 1 to 100 is : %d\n",j); printf("the sum of even numbers 1 to 100 is : %d",o); return 0; }
C++ :
#include<iostream> using namespace std; int main() { int a=0,b=0; for (int x=1,y=2;x<=99&&y<=100;x=x+2,y=y+2) { a=a+x;b=b+y; } cout<<"the sum of odd numbers 1 to 100 is : "<<a<<endl; cout<<"the sum of even numbers 1 to 100 is : "<<b<<endl; return 0; }
- 1
信息
- ID
- 2614
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 0
- 上传者