a = x ;
b = y;
s +=t* a / b;
x = a + b;
y = a;
t = -1.0 * t;
}
Console
.WriteLine(
"s="
+s);
Console
.ReadKey();
}
}
}
实验二
public static void Main() {
int letters = 0, digits = 0, spaces = 0, others = 0;
Console.WriteLine("请输入一个字符串: ");
string input = Console.ReadLine();
foreach(char chr in input)
{ if (char.IsLetter(chr)) letters++;
else if (char.IsNumber(chr)) digits++;
else if (char.IsWhiteSpace(chr)) spaces++;
else others++;
}
Console.WriteLine("
字母的个数为: {0}",letters);
Console.WriteLine("
数字的个数为: {0}", digits);
Console.WriteLine("
空格的个数为: {0}", spaces);
Console.WriteLine("
其他字符的个数为: {0}", others);
}
运行结果