C#乘法表
所以我试图用C#打印一个乘法表,但是我不太明白如何得到我需要的 到目前为止,我的程序输出如下: 1 2 3C#乘法表,c#,loops,multiplication,C#,Loops,Multiplication,所以我试图用C#打印一个乘法表,但是我不太明白如何得到我需要的 到目前为止,我的程序输出如下: 1 2 3 2 4 6 369 但是,我需要它输出以下内容: 01 2 3 1 12 3 2 4 6 369 我尝试了很多不同的方法来获得第二个输出,但是我不太明白。我不一定要问答案,但如果有人能给我指出正确的方向,我将不胜感激 这是我目前拥有的代码: static void Main(string[] args) { for (int i = 1; i <= 3
2 4 6
369 但是,我需要它输出以下内容: 01 2 3
1 12 3
2 4 6
369
我尝试了很多不同的方法来获得第二个输出,但是我不太明白。我不一定要问答案,但如果有人能给我指出正确的方向,我将不胜感激 这是我目前拥有的代码:
static void Main(string[] args)
{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
Console.Write(i * j + "\t");
}
Console.Write("\n");
}
Console.ReadLine();
}
static void Main(字符串[]args)
{
对于(inti=1;ifor(inti=0;i您应该跳过两个0)
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
Console.Write((i == 0? j : (j == 0? i : i*j)) + "\t");
}
Console.Write("\n");
}
for(inti=0;iinttbl=int.Parse(Console.ReadLine());
int j=int.Parse(Console.ReadLine());
对于(inti=1;i,您可以尝试这三种解决方案中的一种
解决方案1(无if-else语句):
static void Main(字符串[]args)
{
for(inti=0;ifor(inti=0;iConsole.WriteLine(“输入数字”);
int j=Convert.ToInt32(Console.ReadLine());
对于(int i=0;i使用系统;
/*
*编写一个基于控制台的应用程序,显示
*1到10之间的每个整数乘以1到10之间的每个整数。保存
*文件名为DisplayMultiplicationTable.cs。
*/
命名空间乘法表
{
班级计划
{
静态void Main(字符串[]参数)
{
Console.WriteLine(“\t\t\t\t\t\t\t\t乘法表”);
Console.WriteLine(“------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------”;
常数int END=11;
对于(int x=1;x
输出
我试图在GUI中完成上述代码。到目前为止,我已经完成了以下代码;但输出与上述输出不同
我的GUI代码如下所示:
使用制度;
使用System.Windows.Forms
命名空间DisplayMultiplicationTableGUI
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
private void ShowTableButton_Click(object sender, EventArgs e)
{
int a;
int b;
const int STOP = 11;
for(a = 1; a < STOP; a++)
{
for(b = 1; b < STOP; b++)
{
int value = a * b;
multiplicationTableLabel.Text += String.Format("{0} * {1} = {2} ", b, a, value);
}
multiplicationTableLabel.Text += "\n";
}
}
}
private void ShowTableButton\u单击(对象发送者,事件参数e)
{
INTA;
int b;
常数int STOP=11;
对于(a=1;a
}第二个输出的第一行应该很简单。只需打印0到n之间的数字。对于其他行,只需在打印乘法表之前打印一个额外的数字。您应该知道打印什么,对吗?您是否应该在这个问题上添加家庭作业标记?您需要乘法表的内容是什么?欢迎使用堆栈溢出。可以吗你可以通过增加至少几个单词来帮助解释来改进你的答案?(使用按钮)请添加一些解释。你想做什么,有什么问题等。我正在为帖子提供答案。
private void ShowTableButton_Click(object sender, EventArgs e)
{
int a;
int b;
const int STOP = 11;
for(a = 1; a < STOP; a++)
{
for(b = 1; b < STOP; b++)
{
int value = a * b;
multiplicationTableLabel.Text += String.Format("{0} * {1} = {2} ", b, a, value);
}
multiplicationTableLabel.Text += "\n";
}
}
}
static void Main(string[] args)
{
for (int i = 0; i <= 3; i++)
{
Console.Write("{0}\t", i);
for (int j = 1; j <= 3; j++)
{
Console.Write("{0}\t", i * j);
}
Console.WriteLine();
}
Console.ReadLine();
}
static void Main(string[] args)
{
for (int i = 0; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
if (i == 0)
{
Console.Write("{0}\t", i);
}
else
{
Console.Write("{0}\t", i * j);
}
}
Console.WriteLine();
}
Console.ReadLine();
}
static void Main(string[] args)
{
for (int i = 0; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
Console.Write("{0}\t", (i == 0) ? i : i * j);
}
Console.WriteLine();
}
Console.ReadLine();
}
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
if (i == 0)
{
Console.Write(j);
}
else
{
if(j == 0)
{
Console.Write(i);
}
else
{
Console.Write(i * j);
}
}
}
Console.Write("\n");
}
Console.WriteLine("Enter A Number");
int j = Convert.ToInt32(Console.ReadLine());
for (int i = 0 ; i <= 10; i++) {
Console.WriteLine("{1} X {0} = {2}",i,j,i*j);
Console.ReadLine();
}
using System;
/*
* Write a console-based application that displays a multiplication table of the product of
* every integer from 1 through 10 multiplied by every integer from 1 through 10. Save the
* file as DisplayMultiplicationTable.cs.
*/
namespace MultiplicationTable
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\t\t\t\t\t\t\t\t\tMultiplication Table");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------------------------------------");
const int END = 11;
for(int x = 1; x < END; x++)
{
for(int y = 1; y < END; y++)
{
int value = x * y;
Console.Write("{0} * {1} = {2}\t", y, x, value);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
private void ShowTableButton_Click(object sender, EventArgs e)
{
int a;
int b;
const int STOP = 11;
for(a = 1; a < STOP; a++)
{
for(b = 1; b < STOP; b++)
{
int value = a * b;
multiplicationTableLabel.Text += String.Format("{0} * {1} = {2} ", b, a, value);
}
multiplicationTableLabel.Text += "\n";
}
}
}