文章分类 -  C/C++打酱油

小知识
摘要:#include <stdio.h>#include <stdlib.h>#include <time.h>#define MAX_NUMBER 100void initialize_number_generator();int new_secret_number();void read_guesses(int secret_number);main(){ char command; int secret_number; printf("Guess the secret number between 1 and %d. \n\n", MA 阅读全文
posted @ 2013-04-24 10:46 He_LiangLiang 阅读(290) 评论(1) 推荐(0) 编辑
摘要:// 一个模拟发牌的程序。#include <stdio.h>#include <stdlib.h>#include <time.h>#define NUM_SUITS 4#define NUM_RANKS 13#define TRUE 1#define FALSE 0typedef int Bool;main(){ Bool in_hand[NUM_SUITS][NUM_RANKS] = {0}; int num_cards, rank, suit; const char rank_code[] = {'2', '3', & 阅读全文
posted @ 2013-04-23 23:59 He_LiangLiang 阅读(419) 评论(1) 推荐(0) 编辑
摘要:几个 Simple 的递归例子 1 #include <iostream> 2 using namespace std; 3 4 // 递归求 n! 5 int fact(int n) 6 { 7 if (n <= 1) 8 return 1; 9 else10 return n * fact(n-1);11 };12 13 // 递归求 x^n (x的n次方)14 int power(int x, int n)15 {16 if (0 == n)17 return 1;18 else19 ret... 阅读全文
posted @ 2013-04-23 23:49 He_LiangLiang 阅读(258) 评论(0) 推荐(0) 编辑
摘要:规律题1:根据以下数字规律,判断最后一个数字是?13 17 29 52 82 ( )【分析】1+3=4, 13+4=17; // 13可以拆为 1, 31+7=8, 17+4+8=29;2+9=11, 29+4+8+11=52;5+2=7, 52+4+8+11+7=82;8+2=10, 82+4+8+11+7+10=122规律题2:根据以下数字规律,判断()中的答案是ABCD中的哪一个?6 4 8 9 12 9 () 26 30 A.12 B.16 C.18 D.22【分析】首尾相对两项相加可组成等差数列, 36, 30, 24, 18, 12.规律题3:根据以下数字... 阅读全文
posted @ 2013-04-23 12:01 He_LiangLiang 阅读(792) 评论(0) 推荐(0) 编辑
摘要:1 //--------------------------------- 【static】 不是 【const】 --------------------------------------- 2 #include <stdio.h> 3 class A 4 { public: 5 // 声明为静态变量 6 static int i; 7 static int j; 8 int k; 9 public:10 A(int k_){k=k_;}11 static void setj(int j_);12 static void p... 阅读全文
posted @ 2013-04-22 07:17 He_LiangLiang 阅读(194) 评论(0) 推荐(0) 编辑
摘要:C语言里面的语法:#include <stdio.h>main(){ // 整数前补0: printf("%03d \n", 28); // --- 028 // 小数后补0: printf("%0.7f \n", 2.1); // --- 2.1000000 return 0;}C++里面的语法:#include <iostream> #include <iomanip>using namespace std; int main() { int n = 28; cout<<setw(3)<<s 阅读全文
posted @ 2013-04-20 21:20 He_LiangLiang 阅读(3205) 评论(0) 推荐(0) 编辑