5.8练习题

#include<iostream>
#define _CRT_SECURE_NO_WARNINGS
#pragma warning (disable: 4996)
using namespace std;
//1
/*
int main() {
	int a;
	int b;
	cout << "Enter the number: ";
	cin >> a;
	cout << "And another: ";
	cin >> b;
	int sum=0;
	for (int i = a; i <= b; i++) {
		sum += i;
	}
	cout << "The sum is " <<sum;
	return 0;
}
*/

//2
/*
#include<array>
int main() {
	array<long double, 16>fac;
	fac[0] = fac[1] = 1L;
	for (int i = 2; i < 16; i++) {
		fac[i] = fac[i - 1] * i;
	}
	for (int i = 0; i < 16; i++) {
		cout << i << "! = " << fac[i] << endl;
	}
	return 0;
}
*/

//3
/*
int main(){
	int i;
	int sum=0;
	cout << "Please enter the number:\n";
	do {
		cin >> i;
		sum += i;
		cout << "The sum is "<< sum << endl;
	}while (i != 0);
	cout << "Ops, 0 is the end.";
	return 0;
}
*/

//4
/*
#include<math.h>
int main() {
	int Daphne=0;
	int Cleo=0;
	int n = 1;
	while (Cleo <= Daphne) {
		Daphne = 100 + 10 * n;
		Cleo = 100 + pow(5, n);
		n++;
	}
	cout << "Daphne's: " << Daphne << endl;
	cout << "Cleo's: " << Cleo << endl;
	cout << "Year: " << n;
	return 0;
}
*/

//5
/*
#include<string>
const int Month = 12;
int main() {
	int tsale=0;
	int *sales = new int[Month];
	string *month = new string[Month];
	month[0] = "Jan.";
	month[1] = "Feb.";
	month[2] = "Mar.";
	month[3] = "Apr.";
	month[4] = "May.";
	month[5] = "Jun.";
	month[6] = "Jul.";
	month[7] = "Aug.";
	month[8] = "Sept.";
	month[9] = "Oct.";
	month[10] = "Nov.";
	month[11] = "Dec.";
	cout << "Enter the sales per month from Feb.: " << endl;
	for (int i = 0; i < Month; i++) {
		month[i];
		int sale;
		//int tsale;
		cin >> sale;
		sales[i] = sale;
		tsale += sale;
		cout << month[i] << ": " << sales[i] << endl;
	}
	cout << "This year we sold " << tsale << " <<C++For Fools>> at all.";
	return 0;
}
*/

//6
/*
#include<string>
const int Year = 3;
const int Month = 12;
int main() {
	int sale = 0;
	int tsale = 0;
	int ttsale = 0;
	string *month = new string[Month];
	month[0] = "Jan.";
	month[1] = "Feb.";
	month[2] = "Mar.";
	month[3] = "Apr.";
	month[4] = "May.";
	month[5] = "Jun.";
	month[6] = "Jul.";
	month[7] = "Aug.";
	month[8] = "Sept.";
	month[9] = "Oct.";
	month[10] = "Nov.";
	month[11] = "Dec.";
	//二维数组不是一个基本类
	//不能直接用new创建
	int **Sales = new int*[Month];
	for (int i = 0; i < Month; i++) {
		Sales[i] = new int[Year];
		//cout << month[i] << ": ";
		for (int n = 0; n < Year; n++) {
			cin >> sale;
			Sales[i][n] = sale;
			//cout << Sales[i][n] << "\t";
		}
	}
	for (int i = 0; i < Month; i++) {
		cout << month[i] << ": ";
		for (int n = 0; n < Year; n++) {
			cout << Sales[i][n] << "\t";
		}
	}
	delete Sales;
	delete month;
	return 0;
}
*/

//7
/*
#include<string>
struct car {
	string producter;
	int year;
};
int main() {
	string p;
	int y;
	int cars;
	cout << "How many cars do you have?";
	cin >> cars;
	car *Cars = new car[cars];
	for (int i = 0; i < cars; i++) {
		cout << "Car #" << i + 1 << endl;
		cout << "Please enter the producter: " ;
		cin >> p;
		cout << "Please enter the year: " ;
		cin >> y;
		Cars[i].producter = p;
		Cars[i].year = y;
	}
	cout << "Here is your collection:\n";
	for (int i = 0; i < cars; i++) {
		cout << Cars[i].year << "  " << Cars[i].producter << endl;
	}
	delete []Cars;
	return 0;
}
*/

//8
/*
int main() {
	const char end[5] = "done";
	char iput[20];
	int count=0;
	cout << "Enter words (to stop, type the word done):" << endl;
	while (strcmp(iput,end)) {
		cin >> iput;
		count++;
	}
	cout << "You entered a total of " << count-1 << " words.";
	return 0;
}
*/

//9
/*
#include<string>
int main() {
	string iput;
	int count = 0;
	cout << "Enter words (to stop, type the word done):" << endl;
	cin >> iput;
	while (iput!="done") {
		count++;
	}
	cout << "You entered a total of " << count  << " words.";
	return 0;
}
*/

//10
#include<string>
int main() {
	int num;
	cout << "Enter number of rows: ";
	cin >> num;
	cout << "\n";
	for (int i = 1; i<=num; i++) {
		for (int n = 0; n < num-i; n++) {
			cout << ". ";
		}
		for (int n = i; n >0;n--) {
			cout << "* ";
		}
		
		cout << "\n";
	}
	return 0;
}

 

转载于:https://my.oschina.net/Almon/blog/3041807

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值