1、输入一个数字 乘以这个数本身 输入-1 结束程序
#include<iostream>
using namespace std;
int main()
int n;
{
while(cin>>n)
{
if(n!=-1)
{
cout<<n*n<<endl;
}
}
return 0;
}
2、编写一个程序,以每公里 0.7 元的价格为员工计算里程报销程序提示用户输入里程表开始的度数和介绍读数,然后计算出此次同行的价格
#include<iostream>
using namespace std;
int main()
{
int a,b;
float c=0.7;
cout<<"请输入开始里程"<<endl;
cin>>a;
cout<<"请输入结束里程"<<endl;
cin>>b;
cout<<"您本次的旅程为"<<(b-a)<<"本次旅程的价格为"<<(b-a)*c<<endl;
system("pause");
return 0;
}
3、作为发票系统的一部分,需要一个程序输入产品的单价和订购的数量。 程序应该输出订单的总成本,前提是订单的前 100 项按单价收取,其余的按单价的 75%收取
#include<iostream>
using namespace std;
int main()
{
float price;
float num;
float sum;
cout << "请输入订单价格"<<endl;
cin >> price;
cout << "请输如订单数量" << endl;
cin >> num;
if (num>100)
{
sum = price * 100 + (num - 100) *( 0.75*price);
}
else
{
sum = price*num ;
}
cout << "你的订单数量为" << num << "你的订单总价为" << sum << endl;
return 0;
}
4、输出int long float double string longlong bool数据类型在内存中所占大小
#include <iostream>
using namespace std;
int main()
{
string s = "q";
cout << "string=" << sizeof(s) << endl;
bool a = false;
cout << "bool=" << sizeof(a)<< endl;
long b = 58949;
cout << "long=" << sizeof(b) << endl;
long long c=456456;
cout << "long long=" << sizeof(c) << endl;
int d = 4;
cout << "int=" << sizeof(d) << endl;
double e = 44.44;
cout << "double=" << sizeof(e) << endl;
float f = 666.6;
cout << "float=" << sizeof(f) << endl;
return 0;
}
5、水仙花数:指一个三位数,他的个位数、十位数、百位数、的三次幂之和等于它本身例如153。
#include <iostream>
using namespace std;
int main()
{
int a= 100;
int gewei = 0;
int shiwei = 0;
int baiwei = 0;
int sum = 0;
int tim = 0;
do
{
gewei = a % 10;
shiwei = a / 10 % 10;
baiwei = a / 100;
if (gewei*gewei *gewei+shiwei *shiwei*shiwei+baiwei*baiwei*baiwei==a)
{
tim = tim + 1;
cout << a << endl;
}
{
}
a=a++;
} while (a<=999);
cout << "有四次" << tim << endl;
return 0;
}
6、敲桌子案例:从数字1到数字100 如果个位或者十位有数字7,则输出敲桌子否则继续输出敲桌子。
#include<iostream>
using namespace std;
int main()
{
for (int i=0; i < 100; i++)
{
int gewei = i % 10;
int shiwei = i / 10 % 10;
if (gewei==7||shiwei==7)
{
cout <<i<< gewei << shiwei << "敲桌子" << endl;
}
else
{
cout << i << endl;
}
}
return 0;
}
7、利用循环输出10*10矩阵 如下图。
#include<iostream>
using namespace std;
int main()
{
for (int i = 0; i <= 9; i++)
{
for (int i = 0; i < 9; i++)
{
cout << "*";
}
cout << endl;
}
}
8、利用循环嵌套输出下面的乘法表。
#include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <=9; i++)
{
for (int j = 1; j <=i ; j++)
{
cout << j << "*" << i << "=" << j * i << " ";
}cout << endl;
}
}
9、输入键盘1打印地狱模式选择成功;输入2打印高手模式成功;输入3打印凡人模式成功,输入其他显示输入错误,请重新输入。
#include<iostream>
using namespace std;
int main()
{
int a;
while (true)
{
cout << "请输入难度1地狱、2高手、3凡人";
cin >> a;
switch (a)
{
case 1:
cout << "地狱难度选择成功";
break;
case 2:
cout << "高手难度选择成功";
break;
case 3:
cout << "凡人难度选择成功";
break;
default:
cout << "错误请重新选择";
break;
}
}
}
10、输出1-100的奇数
#include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 100; i++)
{
if (i%2==0)
{
continue;
}
cout << i << endl;
}
}
以上内容为本人学习笔记,如有不对的地方请多多包涵!