using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class Survey
{
static void Main()
{
Console.WriteLine("1.求数的绝对值");
//创建标签,用来返回
again:
Console.WriteLine("请输入求的数字:");
//定义变量a,b
int a, b;
//获取页面输入的值赋值给a
a = int.Parse(Console.ReadLine());
//如果a为正数
if (a >= 0)
{
//将a的值赋值给b
b = a;
}
//如果为负数
else
{
//将a的绝对值赋值给b
b = -a;
}
Console.WriteLine("答:{0}的绝对值是{1}", a, b + "。");
Console.ReadLine();
//返回标签
goto again;
下面是输出截图:
Console.WriteLine(“2.使用do-while循环计算从1到10的和”);
//创建标签,用来返回
repeat:
int x = 1, y = 0;
do
{
y += x;
}
while
(
x++ < 10
);
Console.WriteLine(“答:从1到10的和是{0}”, y + “。”);
//Console.WriteLine("答:{0}的绝对值是{1}", a, b + "。");
Console.ReadLine();
//返回标签
goto repeat;
}
}
下面是输出截图: