(10) 编程求N=1+2+3+…n 的最大n 值,使N 不超过16 位数的表示范围。

来源:百度知道 编辑:UC知道 时间:2024/05/21 21:55:35

这个是ASP文件的编程方法

const n=100' 自己修改
dim sum=0
if len(n)>16 then
Response.Write("<Script Language='Javascript'>")
Response.Write("alert('你输入的N已经超过16位数');")
Response.Write("history.go(-1);")
Response.Write("</Script>")
Response.End
response.end()
else
for i=1 to n
sum=sum+1
next
response.write "最后N相加的和为:"&sum
end if

#include <iostrem.h>

void main()
{
int i,n;
int sum=0;
for(n=1;;n++)
{
for(i=1;i<=n;i++)
{
sum=sum+i;
}
if(sum<10000000000000000)
continue;
else
cout<<n-1<<endl;
break;
}
}