C++课程内容小结

#include<iostream>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
	cout <<"please enter your first and second names\n";
	string first="first";
	string second="second";
	string name = first + ' ' + second;	// concatenate strings
						// separated by a space
	cout <<"Hello, "<< name << '\n';
	return 0;
}

以上代码主要注意string字符串的相加,可以采用A字符串+' '+B字符串的方式进行编译,最后得出"first second".

#include<iostream>
#include<cmath>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
	cout << "please enter a floating-point number: "; // prompt for a number
	double n=10;					    // floating-point variable
	cout << "n == " << n
		<< "\nn+1 == " << n+1		             // '\n' means “a newline”
		<< "\nthree times n == " << 3*n
		<< "\ntwice n == " << n+n
		<< "\nn squared == " << n*n
		<< "\nhalf of n == " << n/2
		<< "\nsquare root of n == " << sqrt(n)    // library function
		<< endl;				            // another name for newline
}
#include<iostream>
#include<cmath>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
	int a = 20000;
	char c = a;
	int b = c;
	cout<<a<<endl
	    <<b<<endl
	    <<c<<endl;
	if (a != b)	    	//  != means “not equal”
		cout << "oops!: " << a << "!=" << b << '\n';
	else
		cout << "Wow! We have large characters\n";
}

 

#include<iostream>
#include<cmath>
//#include <std_lib_facilities.h>
using namespace std;
// read first and second name:
int main()
{
	int i = 0;
	while (i<100) {
		cout << i << '\t' << sqrt(i) << '\n';
		++i ;	// increment i
	}
}

输出一个0-99的开根号

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值