初学C++ DAY 2
每一天都是新的起点,Believe in yourself!!!
判断三个数中的最大数:
#include<iostream>
using namespace std;
int main()
{
cout<< "请输入三个数:" << endl;
int a, b, c;
cin >> a >> b >> c;
int max;
if (a > b) //判断第一个数的大小;
{
if (a > c)
max = a;
else
max = c;
}
else if (b > c) //判断第二个数的大小;
max = b;
else
max = c;
cout << a << "," << b << "," << "," << c << "中最大的数为:" << max << endl;
return 0;
system("pause");
}
正反三角形:
#include<iostream>
using namespace std;
int main()
{
int space, loop = 5;
for (int i = 0; i < loop; ++i)
{
for (space = 0; space <loop - i; ++space)
{
cout << " ";
}
int k = 2 * i + 1;
while (k > 0)
{
cout << "* ";
--k;
}
cout << endl;
}
for (int i = loop; i >=0; --i)
{
for (space = 0; space <loop - i; ++space)
{
cout << " ";
}
int k = 2 * i + 1;
while (k > 0)
{
cout << "* ";
--k;
}
cout << endl;
}
system("pause");
return 0;
}