C
C语言
喷嚏O(∩_∩)O
这个作者很懒,什么都没留下…
展开
-
合并两个有序链表(递归)
题目:将两个升序链表合并为一个新的升序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 (可以直接用插入合并,会比较麻烦;递归方法理解之后,使用起来灰常灰常地方便) class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if(l1 == NULL) retur...原创 2020-03-29 11:36:05 · 219 阅读 · 0 评论 -
指针(二)之用指针处理链表
建立链表,输出链表 #include <stdio.h> #include <malloc.h> #define LEN sizeof(struct Student) struct Student { long num; float score; struct Student*next; }; int n; struct Student*creat() ...原创 2020-02-05 11:58:41 · 330 阅读 · 0 评论 -
指针(一)之指针变量作为函数参数
先看下例,不通过函数交换指针指向: #include <stdio.h> int main() { int a,b; int *pointer_1,*pointer_2,*p; printf("please input a,b:"); scanf("%d,%d",&a,&b); pointer_1 = &a; pointer_2 = &...原创 2020-02-02 13:09:30 · 1185 阅读 · 0 评论 -
使用牛顿迭代法求根(C)
题目:使用牛顿迭代法求根,方程ax3 + bx2 + cx + d = 0,系数a,b,c,d的值依次是1,2,3,4,由主函数输入,求x再1附近的一个实根。求出主函数输出。 #include <stdio.h> #include <math.h> int main() { double solute(double,double,double,double); //声明解...原创 2020-02-01 20:10:14 · 3629 阅读 · 2 评论 -
静态局部变量VS自动变量(static局部变量VSauto变量)
根据下面的例子更好的了解静态局部变量 #include <stdio.h> int main() { int f(int); int i,a = 2; for(i=0;i<3;i++) printf("%d\n",f(a)); return 0; } int f(int a){ auto int b = 0; static int c = 3; b=b+1...原创 2020-02-01 16:10:01 · 401 阅读 · 0 评论 -
题目:输入一行字符,统计其中有多少个单词,单词之间用空格分隔开(C)
题目:输入一行字符,统计其中有多少个单词,单词之间用空格分隔开(C) #include <stdio.h> #include <string.h> int main() { char string[81]; int i ,num=0,word=0; char c; gets(string); for(i=0;(c=string[i])!='\0';i++){ ...原创 2020-02-01 15:15:24 · 2263 阅读 · 3 评论 -
输入两个正整数m和n,求其最大公约数和最小公倍数 (C)
题目:输入两个正整数m和n,求其最大公约数和最小公倍数 #include <stdio.h> #include <iostream> #include <math.h> int main() { int m,n,i,rem1,rem2; int com_div=1,com_mul=1; scanf("%d,%d",&m,&n); re...原创 2020-02-01 15:07:21 · 698 阅读 · 2 评论