c#MAIN方法例题
时间: 2023-12-07 22:38:23 浏览: 28
以下是两个C#的MAIN方法例题:
1. 求表达式(++a-1)&b+c/2的值
```csharp
using System;
namespace Example1
{
class Program
{
static void Main(string[] args)
{
int a = 3, b = 4, c = 5;
Console.WriteLine((++a - 1) & b + c / 2); // 输出:4
}
}
}
```
2. 输出所有满足条件的三位数:三位数本身等于其每位数字的立方和
```csharp
using System;
namespace Example2
{
class Program
{
static void Main(string[] args)
{
int n, a, b, c;
Console.WriteLine("The number satisfied condition:\n");
for (n = 100; n < 1000; n++)
{
a = n / 100; // 分别取出三位数的百位,十位和各位
b = (n / 10) % 10;
c = n % 10;
if (n == a * a * a + b * b * b + c * c * c) // 判断符合条件,输出结果
{
Console.WriteLine("{0} ", n);
}
}
}
}
}
```