If 语句,条件运算符 && || , 运算符优先级, for 循环语句,switch 语句,continue, break, do, while 打印一个锥形1~9矩阵,打印 9*9 乘法表,
For(初始化; 条件; 每次循环必执行语句)
输出abcd....ABCD....0123....
输出从1~1000,能被7整除的数
While 输入一组数,0为结束,计算他们的和
假设输入 10 5 4 3 2 17 0,计算他们的结果
int main()
{
int a = 1;
int all = 0;
while (a != 0)
{
cin >> a;
if (a == 0)
{
}
else
{
all += a;
}
}
cout << all << "\n";
}
While(条件) 条件也是支持算术表达式的
int main()
{
int a = 100;
while (a /= 2)
{
cout << a << "\n";
}
}
do,while
输入一个数,把他反过来输出到屏幕上,比如输入 256,输出 652
int main()
{
int a = 0;
cin >> a;
//256
//652
do
{
int b = a % 10;
a /= 10; // 25 //2
cout << b;
} while (a > 0);
}
两重循环
从1~100,输出 1, 1 +2, 1+2+3, 1+2+...+n 的结果
int main()
{
int a = 0;
int i = 0;
for (int i = 1; i <= 100; i++)
{
int result = 0;
for (int j = 1; j <= i; j++)
{
result += j;
}
cout << result;
cout << "\n";
}
}
输出下列图形
1
12
123
1234
12345
....
- ..9
int main()
{
int a = 0;
int i = 0;
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
cout << j;
}
cout << "\n";
}
}
三重循环
你有100元,铅笔2元一只,橡皮4元一个,卷笔刀7元一个,列出你能买的所有可能集合,结果之间换行显示
int main()
{
for (int i = 1; i <= 100; i++)
{
for (int j = 1; j <= 100; j++)
{
for (int k = 1; k <= 100; k++)
{
if (i * 2 + j * 4 + k * 7 == 100)
{
cout << "铅笔" << i << " " << "橡皮" << j << " " << "卷笔刀" << k << " ";
cout << "\n";
}
}
}
}
}
int main()
{
int a = 429;
int b = 723;
for (int i = 429; i > 0; i--)
{
if (a % i == 0 && b % i == 0)
{
cout << i << "\n";
break;
}
}
}
}
标签:cout,int,....,编程,基础,C++,while,100,main From: https://blog.csdn.net/m0_62022692/article/details/143781002