1 条题解

  • 0
    @ 2025-9-9 23:46:51

    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

    信息

    ID
    1018
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者