网站快速备案价格,河南建设厅网站地址,wordpress 二手市场,wordpress的ajax好慢练习1#xff1a;数据类型
请写出以下几个数据的数据类型 整数 a a 的地址 存放a的数组 b 存放a的地址的数组 b的地址 c的地址 指向 printf 函数的指针 d 存放 d的数组 整数 a 的类型 数据类型是 int a 的地址 数据类型是 int*#xff08;指向 int 类型的指针#xff09; …练习1数据类型
请写出以下几个数据的数据类型 整数 a a 的地址 存放a的数组 b 存放a的地址的数组 b的地址 c的地址 指向 printf 函数的指针 d 存放 d的数组 整数 a 的类型 数据类型是 int a 的地址 数据类型是 int*指向 int 类型的指针 存放 a 的数组 b 数据类型是 int[]整型数组 存放 a 的地址的数组 c 数据类型是 int*[]指针数组每个元素是指向 int 的指针 c的数据类型是指针数组类型可以表示为int * c[ ] {a}; b 的地址 指向整型数组的指针 b的数据类型是 int(*)[](数组指针)b 的地址可以表示为: b, b, b[0] c 的地址 数据类型是 int*(*)[]指向指针数组的指针 指向 printf 函数的指针 d printf 函数的类型是 int(*)(const char*, ...)d 的数据类型是 int(*)(const char*, ...) 存放 d 的数组 数据类型是 int(*[])(const char*, ...)函数指针数组每个元素是指向 printf 函数的指针。 #include stdio.hint main() {// 打印 Hello, World! 到控制台printf(Hello, World!\n);// 定义一个整型变量 a并初始化为 10int a 10;// 打印变量 a 的地址printf(a的地址是%p\n, a);// 定义一个整型数组 b并将 a 的值存入数组中int b[] {a};// 定义一个整型指针 c并将 a 的地址赋值给它int * c[] {a};// 下面的注释是对 b 和 c 的说明// b, b, b[0]; // b 是数组名b 是数组的地址b[0] 是数组第一个元素的地址// c, c, c[0]; // c 是指针c 是指针的地址c[0] 是指针指向的第一个元素的地址// 定义一个指向 printf 函数的指针 funcs_dint (*funcs_d)(const char*, ...) printf; // 指向printf函数的指针// 定义一个数组 d存放指向 printf 函数的指针int (*d[])(const char*, ...) {printf}; // 存放指向printf函数的指针的数组return 0; // 返回 0表示程序正常结束
} 练习2递归
请用递归实现计算:11/3-1/51/7-1/9…. 1/n 的值n通过键盘输入 #include stdio.h
#include string.h
#include unistd.h
#include stdlib.h
#include sys/types.h
#include sys/stat.h
#include fcntl.h
#include pthread.h
#include semaphore.h
#include wait.h
#include signal.h
#include sys/socket.h
#include arpa/inet.h
#include sys/socket.h
#include sys/ipc.h
#include sys/sem.h
#include semaphore.h
#include sys/msg.h
#include sys/shm.h
#include sys/un.htypedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;double rec_add(int n)
{double sum0;if (n1){return 1;}else{double sum1.0/n;if ((n/2)%20){return sumrec_add(n-2);}else{return -sumrec_add(n-2); }}return sum;
}int main(int argc, const char *argv[])
{int n0;printf(输入n(奇数:);scanf(%d,n);if (n0 ||n%20){printf(重新输入一个正奇数\n);return 1;}double resultrec_add(n);printf(result%f\n,result);return 0;
}练习3写一个双向链表的快速排序函数 #include stdio.h
#include stdlib.h// 双向链表节点结构体
typedef struct Node {int data;struct Node *prev;struct Node *next;
} Node;// 创建新的节点
Node* create_node(int data) {Node *new_node (Node*)malloc(sizeof(Node));new_node-data data;new_node-prev new_node-next NULL;return new_node;
}// 在链表尾部插入节点
void append(Node **head, int data) {Node *new_node create_node(data);if (*head NULL) {*head new_node;} else {Node *temp *head;while (temp-next ! NULL) {temp temp-next;}temp-next new_node;new_node-prev temp;}
}// 打印链表
void print_list(Node *head) {Node *temp head;while (temp ! NULL) {printf(%d , temp-data);temp temp-next;}printf(\n);
}// 切分链表并返回基准节点
Node* partition(Node *low, Node *high) {int pivot high-data;Node *i low-prev;Node *j low;while (j ! high) {if (j-data pivot) {i (i NULL) ? low : i-next;int temp i-data;i-data j-data;j-data temp;}j j-next;}i (i NULL) ? low : i-next;int temp i-data;i-data high-data;high-data temp;return i;
}// 快速排序递归函数
void quick_sort(Node *low, Node *high) {if (low ! NULL high ! NULL low ! high low ! high-next) {Node *p partition(low, high);quick_sort(low, p-prev);quick_sort(p-next, high);}
}// 获取链表的最后一个节点
Node* get_tail(Node *head) {while (head ! NULL head-next ! NULL) {head head-next;}return head;
}int main() {Node *head NULL;// 插入一些数据到链表append(head, 5);append(head, 3);append(head, 8);append(head, 4);append(head, 1);append(head, 7);printf(Original list: );print_list(head);Node *tail get_tail(head);// 执行快速排序quick_sort(head, tail);printf(Sorted list: );print_list(head);return 0;
}