用C#写一个程序,计算0到10的平方和立方。这个程序不需要用户输入。

来源:百度知道 编辑:UC知道 时间:2024/05/10 11:46:47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{

for (int n = 0; n <= 10; n++)
{
int square;
int cube;
square = n * n;
cube = n * n * n;
Console.Write("{0}\t{1}\t{2}","n","square","cube");
}
}
}
}
这个为什么不可以正常运行?

Console.Write("{0}\t{1}\t{2}","n","square","cube");
去掉引号!!!
Console.Write("{0}\t{1}\t{2}",n,square,cube);

for (int n = 0; n <= 10; n++)
{
int square;
int cube;
square = n * n;
cube = n * n * n;
Console.WriteLine("{0}\t{1}\t{2}", n, square, cube);

}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 11; i++)
{
Console.WriteLine(i+"的平方="+i*i+"\t"+i+"的立方="+i*i*i);
}

}
}
}

感觉你的 Console.Writ