
C/C++
Marcus_Liew
简单的人 简单的梦想
展开
-
打乱数组顺序
#include <stdio.h>#include <stdlib.h>#include <time.h>#define ARRAY_SIZE 50int ElementSwitch(int a[], int first, int second){ int tmp; tmp = a[first]; a[first] = a[second]; a[second] = tmp; return 0;}int Shuffle(int a[].原创 2021-09-24 13:03:24 · 436 阅读 · 1 评论 -
C 基本线程
#include <stdio.h>#include "tinycthread.h"int SayHello(char *name){ printf("Run in new thread [%#x]: Hello, %s\n", thrd_current(), name); return 0;}int main(void){ thrd_t new_thread; int result = thrd_create(&new_thread, SayHello, .原创 2021-09-23 17:55:43 · 147 阅读 · 0 评论 -
N的阶乘,递归
#include <stdio.h>unsigned Factorial(unsigned n){ if(n == 0){ return 1; } else{ return n * Factorial(n - 1); }}int main(void){ printf("3! %d\n", Factorial(3)); printf("5! %d\n", Factorial(5)); printf("8! %d\n", Factorial(8)).原创 2021-09-23 15:12:44 · 215 阅读 · 0 评论 -
C语言 变长参数
#include <stdio.h>#include <stdarg.h>void HandleVarargs(int arg_count, ...){ //定义 va_list用于获取变长参数 va_list args; //开始便利 va_start(args, arg_count); for (int i = 0; i < arg_count; ++i) { //取出对应参数 int arg = va_arg(args, int).原创 2021-09-23 14:42:29 · 121 阅读 · 0 评论 -
按值传递 和 按地址传递的例子
点击(此处)折叠或打开 #include stdio.h> void myswap(int, int); void ptr_myswap(int*, int*); int main(){原创 2014-03-05 17:08:36 · 1136 阅读 · 0 评论 -
函数调用中的类型转换 c提升规则
浮点型参数输入到浮点型返回值的函数中,返回正确的值,20.25 点击(此处)折叠或打开 #include stdio.h> /* declaration */ float square(float);原创 2014-03-05 17:06:42 · 738 阅读 · 0 评论 -
简单函数调用 计算1-100每个数的平方
点击(此处)折叠或打开 #includestdio.h> /* function prototype */ int square(int); /* main */ int main(){原创 2014-03-05 17:06:37 · 1969 阅读 · 0 评论 -
统计
点击(此处)折叠或打开 /* The base salary is $200 per-week, bonus is sale * 9%, input the sale, output actual salary */ #includestdio.h> int main(){原创 2014-03-05 17:06:35 · 612 阅读 · 0 评论 -
判断奇数偶数
点击(此处)折叠或打开 #includestdio.h> int main(){ int int_number; printf("please enter a integer: "); scanf("%原创 2014-03-05 17:06:17 · 1419 阅读 · 0 评论 -
计算平方、立方
点击(此处)折叠或打开 #includestdio.h> int main(){ int i; printf("number\tsquare\tcube\t\n");原创 2014-03-05 17:06:08 · 1056 阅读 · 0 评论 -
链表学习笔记(一)
从这篇博文学到的,由衷感谢panda点击打开链接/*名称:初始化链表(1)(直接改变主调函数中的指针head)功能:制造一个头节点接收:指向节点的指针地址 &head返回:int*/int ref_initLink(struct node **L){ //L为指向head(指向节点的指针)的指针,用L接收head的地址 //L接收到head的地址(&head)后,用malloc原创 2014-03-06 11:56:41 · 657 阅读 · 0 评论 -
在屏幕中打印9*9的菱形
点击(此处)折叠或打开 #include stdio.h> #include math.h> int main(){ /* declaration */ int x;原创 2014-03-05 17:06:33 · 930 阅读 · 0 评论 -
计算随机输入数字的平均值
点击(此处)折叠或打开 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @file * @author Sam Liu * @rem原创 2014-03-05 17:06:27 · 1442 阅读 · 0 评论 -
掷骰子20次 统计结果
点击(此处)折叠或打开 #include stdio.h> #include stdlib.h> /* main */ int main(void){ int x;原创 2014-03-05 17:06:44 · 2191 阅读 · 0 评论 -
计算两整数的和
/* C How to program 2.3 */ /* Input:2 integers */ /* Output:add the two integer */ #includestdio.h> int main() { /* Decla原创 2014-03-05 17:06:22 · 677 阅读 · 0 评论 -
学习转义字符串的应用
#includestdio.h> int main() { int x; int y; int z; int result; int intInput; p原创 2014-03-05 17:06:25 · 570 阅读 · 0 评论 -
globe variable and local variable testing
点击(此处)折叠或打开 #includestdio.h> void fun_a(void); /* function prototype */ void fun_b(void); /* function prototype */原创 2014-03-05 17:07:05 · 630 阅读 · 0 评论 -
Fibonacci
点击(此处)折叠或打开 #include stdio.h> int main(){ /* declaration the variable */ int i_end;原创 2014-03-05 17:06:55 · 498 阅读 · 0 评论 -
掷骰子统计各个面出现的次数 调用函数实现 使用全局变量
点击(此处)折叠或打开 #include stdio.h> #include stdlib.h> /* declaration and initialize globe variable */ int FREQUENCY1 =原创 2014-03-05 17:06:47 · 2236 阅读 · 0 评论 -
计算两数加、减、乘、除、取模
点击(此处)折叠或打开 /* Calculation two integers + * - / % */ /* Input: two integers */ /* Output: the sam is: the differ原创 2014-03-05 17:06:20 · 1894 阅读 · 0 评论 -
线性表操作
/***name: create a seqlistreceive: seqlist addressreturn: int***/int creat(Seqlist* L){ int len; L->length = 0; printf("Enter the length of the seqlist:"); scanf("%d", &len); if (len <= 100)原创 2014-03-11 16:30:56 · 629 阅读 · 0 评论 -
读取系统时间作为seed 随机打印数字
点击(此处)折叠或打开 #include stdio.h> #include stdlib.h> #include time.h> int main(){原创 2014-03-05 17:06:58 · 1383 阅读 · 0 评论 -
简单函数调用2
点击(此处)折叠或打开 #include stdio.h> /* declaration */ int myadd(int , int); /* 等价于 int myadd(int a, int b); */ /* main原创 2014-03-05 17:06:40 · 615 阅读 · 0 评论 -
三元表达式
#includestdio.h> int main(){ int int_score; printf("Please Enter a score:"); scanf("%d", &int_score); printf("%s", int_score >=原创 2014-03-05 17:06:10 · 781 阅读 · 0 评论 -
顺序栈的一般操作
#include //define the size of array#define MAXSIZE 100//define new data type: stackstruct stack{ int data[MAXSIZE]; int top;};//defint var seqStacktypedef struct stack seqStack;//crea原创 2014-03-11 22:28:51 · 541 阅读 · 0 评论 -
if嵌套 阶梯判断
点击(此处)折叠或打开 #includestdio.h> int main(){ int int_score; printf("%s", "Please enter a score: "); scanf原创 2014-03-05 17:06:15 · 967 阅读 · 0 评论 -
头插法插入链表节点
/*名称:头插法插入链表节点功能:在链表头节点后插入一个链表节点接收:链表头节点head, 插入节点的int型数据返回:int*/int insertLink_head(struct node* L, int data){ //定义一个指向链表节点的指针 struct node *nodePtr; //当链表为空链表时 if ((L->next) == NULL){ //给原创 2014-03-07 15:09:51 · 1588 阅读 · 0 评论 -
建立一个菜单用来控制链表
/*名称:菜单功能:建立一个菜单用来控制链表接收:void返回:int*/int menulink(void){ struct node *head = NULL; int data = 0, deldata = 0; int choose; printf("************* LINK LIST MENU *************\n"); printf("\t1原创 2014-03-07 22:08:23 · 1209 阅读 · 0 评论 -
一个斐波那契数列
#include #define FIBONSIZE 20int main(){ int a = 0, b = 1, c, fibon[FIBONSIZE]; for (int i = 0; i < FIBONSIZE; i++){ c = a + b; fibon[i] = c; a = b; b = c; } for (int i = 0; i < FIBONS原创 2014-03-18 09:31:55 · 552 阅读 · 0 评论 -
(一)顺序栈头文件
#include #include #define STACKMAXSIZE 10typedef struct seqstack{ int data[STACKMAXSIZE]; int top;}SeqStack;int initSeqStack(SeqStack*);int destroySeqStack(SeqStack*);int clearS原创 2014-03-18 21:03:46 · 1709 阅读 · 0 评论 -
一个c++小程序
#include int mycube(int);using namespace std;int main(){ int side; cout << "enter the cube side: " << endl; cin >> side; cout << "the volume of the cube is: " << mycube(side) <<原创 2014-03-18 21:29:17 · 660 阅读 · 0 评论 -
(二)顺序栈函数定义
#include "seqstack.h"int initSeqStack(SeqStack* S){ S->top = 0; return 0;}int clearSeqStack(SeqStack* S){ for (int i=0; itop; i++) S->data[i] = 0; S->top = 0; return 0原创 2014-03-18 21:04:53 · 894 阅读 · 0 评论 -
(三)顺序栈main函数
#include "seqstack.h"int main(){ SeqStack stack; initSeqStack(&stack); printf("%d\n", isEmptySeqStack(stack)); PushSeqStack(&stack, 111); PushSeqStack(&stack,原创 2014-03-18 21:05:46 · 3170 阅读 · 2 评论 -
function overload 2
#include #include using namespace std;int square(int);double square(double);int main(){ cout << square(8) << endl; cout << square(9.3) << endl; return 0;}int square(int edge){原创 2014-03-19 23:25:12 · 824 阅读 · 0 评论 -
function overload
#include #include using namespace std;int square(int);double square(double);int main(){ cout << square(8) << endl; cout << square(9.3) << endl; return 0;}int square(int edge){原创 2014-03-19 23:17:57 · 736 阅读 · 0 评论 -
简单的函数模版
#include using namespace std;template T volume(T side1, T side2, T side3){ return side1 * side2 * side3;}int main(){ cout << volume(1, 2, 3) << endl; cout << volume(1.2, 2.0, 3.3) << endl;原创 2014-03-20 11:32:19 · 562 阅读 · 0 评论 -
一个简单的类 和 调用
#include using namespace std;class Time{public: //构造函数 Time(); //设置时间函数 void setTime(int, int, int); //24小时制显示时间 void showTime24(); //12小时制显示时间 void showTime12();private: int hour; int原创 2014-03-21 12:51:32 · 584 阅读 · 0 评论 -
(二)链表头文件
#include #include //define a link node structtypedef struct linklistnode{ int data; struct linklistnode *next;}linklist, *linklistPtr;//declaration create_linklistint create_linklist(l原创 2014-03-15 23:43:22 · 973 阅读 · 0 评论 -
(三)链表main函数
#include "linklist.h"int main(){ linklistPtr head; create_linklist(&head); printf("%d\n", head->data); insert_linklist(&head); traversal_linklist(head); del_linklis原创 2014-03-15 23:44:20 · 2610 阅读 · 0 评论 -
(二)函数定义文件
#include "seqlist.h"//1 创建一个顺序表int create_SqList(SqListPtr L){ for (int i = 0; i < LISTMAXSIZE; i++) L->data[i] = 0; L->length = 0; return 0;}//2 判断顺序表是否为空int isEmpty_SqList(SqList L){ re原创 2014-03-14 17:26:50 · 765 阅读 · 0 评论