1 solutions
-
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; }Pascal :
program aa; var a,b,c,d:integer; begin a:=2525; b:=2525; writeln('the sum of odd numbers 1 to 100 is : 2500'); write('the sum of even numbers 1 to 100 is : 2550'); end.
- 1
Information
- ID
- 16254
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By