![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
基础练习
文章平均质量分 51
吴之为吴
只要能忘记曾经,你就能自由,你就能重生。
展开
-
等比数列求和
/*等比数列求和输入:输入数据不多于50对,每对数据含有一个整数n(1<=n<=20),一个小数q(0<q<2)输出:求和,1+q^2+...+q^n 精确到小数点后3位*/#include #include #include using namespace std;int main(){ int n; double q, sum = 0.0; while(cin >>原创 2013-11-08 23:30:39 · 2111 阅读 · 0 评论 -
斐波那契数
//输入:正整数n(0<=n<=46)//输出:第n项斐波那契数//Tips: 先把前46项斐波那契数求粗来,放到数组中或向量中#include #include using namespace std;int main(){ int n; vector v; v.push_back(0); v.push_back(1); for(int k = 2; k <= 46;原创 2013-11-08 23:55:43 · 409 阅读 · 0 评论 -
字符串处理
/*输入:2 ABC ABBCCC输出: ABC A2B3CTips:一边处理,一边输出*/#include #include using namespace std;int main(){ int n; cin >> n; string s, t; while(n--) { cin >> s; t = s[0];原创 2013-11-10 00:52:37 · 389 阅读 · 0 评论 -
列出完数
//完数是指一个数恰好等于它的所有不同因子之和//比如 6 = 3 + 2 + 1//输入 n(1 <= n <= 10000) 输出不大于n的所有完数#include #include using namespace std;int main(){ int sum; int i, j; int n; vector v; for(i = 2; i <=10000; i++原创 2013-11-11 23:32:34 · 680 阅读 · 0 评论 -
十进制转化为二进制
#include #include #include using namespace std;int main(){ int n; string str; while(cin >> n) { if(n == 0) cout << 0 << endl; else { for(int x = n; x; x/=2) { if(x%2 == 0)原创 2013-11-11 23:34:46 · 512 阅读 · 0 评论