工大机试23题

来源:互联网 发布:discuz论坛app源码 编辑:程序博客网 时间:2024/05/04 18:16

 计算 S=1×2+3×4+5×6+…+39×40

// problem23.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 int a=1,b=2;
 int S=0;
 for(;a<40;)
 {
  S+=a*b;
  a+=2;
  b+=2;
 }
 cout<<S<<endl;
 return 0;
}