数学运算符,算数运算符
+
-
*
/
取模运算%
5%2 = 1
6%2 = 0
7%2 = 1
8%2 = 0
9%2 = 1
10%2= 0
11%2 = 1
数学运算符,算数运算符
+
-
*
/
取模运算%
5%2 = 1
6%2 = 0
7%2 = 1
8%2 = 0
9%2 = 1
10%2= 0
11%2 = 1
Console.WriteLine("Hello World!")
Console.WriteLine("Hello World!");
//加注释
单行注释
多行注释/* */
int x = rd.Next(1, 101);//生成一个伪随机数
Console.WriteLine("猜数字");
while (true)//死循环 当猜中了跳出循环
{
int a = Convert.ToInt32(Console.ReadLine());
if (a < x)
{
Console.WriteLine("猜小了");
}else if (a > x)
{
Console.WriteLine("猜大了");
}else
{
Console.WriteLine("猜中了");
break;
}
}
Console.ReadKey();
//输⼊两个整数num1和num2,输出这两个正整数num1和num2的最⼤公约数。
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int min = a;//定义最小值为min
if (b < a)//保持min是最小的
{
min = b;
}
for (int i = min ; i > 0; i--)//从大到小遍历输入的较小值到1
{
if (a % i == 0 && b % i == 0)//如果同时是a,b的因数就是最大公约数
{
Console.WriteLine(i);
break;//只需要输出一个
}
}
Console.ReadKey();
int a = 5 b =10;
int temp = a ;
a = b;
b= temp ;
其他解法下面解法内存占用多
a = a +b;
b = a- b;
a = a- b;
题1
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(a+b);
题2
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(a/b);
题3
除了4 都正确
题4
A
题5
A
string str = "132"+"456";
string str2 = str +"www";
console.writeline("www"+123);
string str = console .readline();
console.writeline(str +"-");
1 类型一致
2 右边的值所需要的容器大小,小于等于左边的容器
string a = Console.ReadLine();
int a1 = Convert.ToInt32(a);
string b = Console.ReadLine();
int b1 = Convert.ToInt32(b);
Console.WriteLine(a1+b1);
int a = console.readl
\n 为特殊字符
@ 为直接转译字符
Console.WriteLine("a:\\c\\b\\a");
Console.WriteLine(@"a:\c\b\a");
两段代码得输出结果是一致的
字符串不能多行必须连贯,只能在同一行
加入了@后就可以了
字符存储为数字
按十进制 字符c底层存储是99 a=97
ASCII字符代码表(十进制)
int a = 97;
char b = a;
赋值两边要一致,
赋值小容器的可以赋值给大容器
大容器无法赋值给小容器
char b = (char)a;//强制类型转换 强塞
23 = a; 错误 变量不能数字命名
a = b+c;对
x+y=z;错
a=a+1;对
int a =1;
a= 3+7-2;
int b = 3;
b = b+ 1;// b = 4
c = 4
c = 7
c = 16
a = 16
a = 48
11
a+b
3+8
a+b38
a+b11
int age;
int jishuqi;
double pingjunshu;
double shengao;
double zonghe;
double char;
int count;
double ave;
double height;
int total;
double temperature;
total = 4;
学会用思维导图
程序入口方法Main方法
练习题答案
1题:
错
错
对
错
错
对
2题
c
3题
Console.WriteLine("*\n**\n***\n****\n*\n*\n*");
4题
Console.WriteLine(" *\n ***\n *****\n *******\n *\n *\n *");
5题
d
6题
Console.WriteLine("SiKi说:\"What is \\n\"");
数字+字符串 //组拼
double
double
double
double
d
整数
浮点数
‘字符’
“字符串”
光标开头:home
结尾:end
Main方法:入口方法,一个项目只有一个入口方法
//int a = 0;//乘积
for (int i = 1; i <=9; i++)//9行
{
for (int j = 1; j <=i; j++)//9 列
{
//a = i * j;
Console.Write("{0}x{1}={2} ",j,i,j*i);//j*i=a 加两个空格隔开
}
Console.WriteLine();
}
Console.ReadKey();
//⽤100⽂买⼀百只鸡,其中公鸡,⺟鸡,⼩鸡,都必须要有,公鸡3⽂⼀只,⺟鸡5⽂⼀只,⼩鸡
//2⽂⼀只,请问公鸡、⺟鸡、⼩鸡要买多少只刚好凑⾜100⽂。把所有的满⾜条件的情况罗列出来。
//公鸡 3
//母鸡 5
//小鸡 2
//定义a, b, c;三个变量 分别是abc只
for (int a = 0; a <= 100/3; a++)//全买公鸡的最大个数
{
for (int b = 0; b <= 100 / 5; b++)//母鸡
{
for (int c = 0; c <= 100 / 2; c++)//小鸡
{
if (3 * a + 5 * b + 2 * c == 100)//判断是否刚好为100
{
Console.WriteLine("公鸡{0}只 母鸡{1}只 小鸡{2}只",a,b,c);
}
}
}
}
Console.ReadKey();