1.用一百元买一百只鸡,公鸡5元一只,母鸡3元一只,小鸡1元三只
2.定义一个结构体,给结构体赋值将结构体的值输出
答案:
1.保证总共花了100元,遍历所有能买鸡的情况,输出买鸡数为100的情况。
static void Main(string[] args)
{
int count = 0;
for(int i = 0; i <= 100 / 5; i++)
{
for(int j = 0; j <= (100 - 5 * i) / 3; j++)
{
count = i + j + (100 - 5 * i - 3 * j) * 3;
if(count == 100)
{
Console.WriteLine("公鸡 " + i + "母鸡" + j + "小鸡" + (100 - 5 * i - 3 * j) * 3);
}
}
}
Console.ReadKey();
}
2.
struct student
{
public string number;
public string name;
public bool isGirl;
public int age;
public void show()
{
Console.WriteLine("ID:" + number + "\nname:" + name +
" is a" + (isGirl ? "Girl" : "Man") + "\nage: " + age);
}
}
static public int Mult(int n)
{
if (n == 1)
{
return 1;
}
else
{
return n * Mult(n - 1);
}
}
static void Main(string[] args)
{
//Console.WriteLine(Mult(5));
student jj;
jj.number = "001";
jj.name = "jiaojiao";
jj.isGirl = false;
jj.age = 25;
jj.show();
Console.ReadKey();
}
}