C++学习记录_1

//carrots.cpp
#include <iostream>
using namespace std;

int main()
{
	int carrots;
	carrots = 25;

	cout << "I have " << carrots << "carrots.\n";

	carrots--;
	cout << "Crunch, crunch.Now I have " << carrots << " carrots." <<endl;

	return 0;
}
//convert.cpp
#include <iostream>
using namespace std;

int stonetolb(int);

int main()
{
	int stone;
	cout << "Enter the weight in stone:";
	cin >> stone;
	int pounds = stonetolb(stone);
	cout << stone
	     << " stone = "
	     << pounds
	     << " pounds."
	     << endl;

	return 0;
}

int stonetolb(int sts)
{
	return 14 * sts;
}
//getinfo.cpp
#include <iostream>
using namespace std;

int main()
{
	int carrots;
	cout << "How many carrots do you have?" << endl;
	cin >> carrots;
	cout << "Here are two more.";
	carrots += 2;
	cout << "Now you have " << carrots << " carrots." << endl;

	return 0;
}
//ourfunc.cpp
#include <iostream>
using namespace std;

void simon(int);

int main()
{
	simon(3);
	cout << "Pick an integer:";
	int count;
	cin >> count;
	simon(count);
	cout << "Done!" << endl;
	
	return 0;
}

void simon(int n)
{
	cout << "Simon says touch your toes "
	     << n
	     << " times."
	     << endl;
}
//sqrt.cpp
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	double area;
	cout << "Enter the floor area, in square feet, of your home:";
	cin >> area;
	double side;
	side = sqrt(area);
	cout << "That's the equivalent of a square "
	     << side
	     << " feet to the side."
	     << endl
	     << "How fascinating!"
	     << endl;

	return 0;
}
//limits.cpp
#include<iostream>
#include<climits>
using namespace std;

int main()
{
	int n_int = INT_MAX;
	short n_short = SHRT_MAX;
	long n_long = LONG_MAX;
	long long n_llong = LLONG_MAX;

	cout << "int is " << sizeof(int) << " bytes." << endl;
	cout << "short is " << sizeof(short) << " byres." << endl;
	cout << "long is " << sizeof(long) << " bytes." << endl;
	cout << "long long is " << sizeof(long long) << " bytes."
	     << endl << endl;

	cout << "Maximum values:" << endl
	     << "int: " << n_int << endl
	     << "short: " << n_short << endl
	     << "long: " << n_long << endl
	     << "long long: " << n_llong << endl
	     << endl;

	cout << "Minimum int values = " << INT_MIN << endl
	     << "Bits per bytes = " << CHAR_BIT << endl;

	return 0;
}

猜你喜欢

转载自blog.csdn.net/x18261294286/article/details/81346781