c#编程输出1~1000之间所有的 完全平方数(时间有限,好的加分)

如题所述

第1个回答  推荐于2016-07-10
新建一个c#控制台程序 把代码复制到新建的项目里面就行
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main()
{
int[] a = new int[1000];
int i,j,n;
for (i = 1; i <= 1000; i++)
{
a[i - 1] = i;
}
n = Convert.ToInt32(Math.Sqrt(1000));
for (i = 1; i <= 1000; i++)
{
for (j = 1; j <= n; j++)
{
if (a[i - 1] == j * j)
{
Console.WriteLine(a[i-1]);
}
}
}
}
}
}追问

class Program
{
static void Main(string[] args)
{
for (int i = 0; i <= 10000; i++)
{
if(Math.Sqrt(i) == Math.Truncate(Math.Sqrt(i)))
Console.Write(i + " ");
}
}
}
谢了哈

本回答被提问者采纳
相似回答