C# 求一个数的平方的公式

C# 求一个数的平方的公式,c#,.net,for-loop,perfect-square,C#,.net,For Loop,Perfect Square,我需要使用for循环显示数字1-10的平方。这就是我目前所拥有的。我不知道我错过了什么。任何帮助都将不胜感激 for (int counter = 1; counter <= 10; counter++) { Console.WriteLine(counter * counter); } Console.ReadLine

我需要使用for循环显示数字1-10的平方。这就是我目前所拥有的。我不知道我错过了什么。任何帮助都将不胜感激

        for (int counter = 1; counter <= 10; counter++)
        {                          
            Console.WriteLine(counter * counter);                
        }
        Console.ReadLine();
for(int counter=1;counter试试这个

    for (int counter = 1; counter <= 10; counter++)
    {          
            Console.WriteLine(counter*counter);
    }

对于(int counter=1;counter对于整数
计数器
具有除
0
以外的任何值,
计数器*计数器
将永远不会计算为
0

如果((计数器*计数器)==0)这将不满足任何值..尝试一下如果((计数器*计数器)!=0)…试试这个..

看看你的代码

for (int counter = 1; counter <= 10; counter++)
{
   if ((counter * counter) == 0) // this will never evaluate to true
   {
       Console.WriteLine(counter);
   }
}

for(int counter=1;counter由于从1开始,计数器*计数器不能为0。因此,记住这一点,下面是全部代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication21
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 10; i++)
                Console.WriteLine(i * i);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间控制台应用程序21
{
班级计划
{
静态void Main(字符串[]参数)
{

对于(int i=1;i hmmm,由于某些原因,我没有得到任何输出在更新后显示您的完整代码。我想您没有删除计算为false的if条件。@Vinnie,将其括在backticks
中,如:`code`,请参见?
,但只有短片段适合于注释。
code:for(int counter=1;counter出于某种原因,我不得不重新启动visual studio,它工作了。+1对于代码来说是非常好的。它正在按预期生成输出。您可以放置一个断点并查看它是否正在执行吗?还有一个问题,我将如何执行1=sqaure,然后执行2=square,依此类推
Console.WriteLine(“Number:{0},square:{1}”,counter,counter*counter);
控制台。WriteLine(counter=(counter*counter));
。带上一些教程,太棒了,非常感谢!!!!