`
carolaif
  • 浏览: 70624 次
  • 性别: Icon_minigender_2
  • 来自: 大连
最近访客 更多访客>>
社区版块
存档分类
最新评论
文章列表
编写一个递归版本的reverse()函数,将字符串倒置   #include<stdio.h> void reverse(char *s); int main(){ char *s ="hello"; reverse(s); return 0; } void reverse(char *s){ char line =*s; if(line){ reverse(++s); printf("%c",line); } }   递归函数的参数变化是关键,最好使递归到达最底层的条件一定是参数
运用printd函数的设计思想编写一个递归版本的itoa函数,即通过递归调用把整数转换为字符串   #include <stdlib.h> #include <stdio.h> /*思路:先调用itoa,在itoa中判断int型value是正还是负,无论正负,将value转换成unsigned型,然后调用utoa*/ char *utoa(unsigned value, char *digits, int base) { char *s, *p; s = "0123456789abcdef"; /* ...
从执行速度来讲,下列版本的快速排序可能不是最快的,但是它是最简单的算法之一。在每次划分子集时,该算法总是选取各个子数组的中间元素,(作为划分子集的基准)。   /* qsort: 以递增顺序对v[left]...v[right]进行排序 */ void qsort(int v[], int left, int right) { int i, last; void swap(int v[], int i, int j); if (left >= right) /* 若数组包含的元素数少于两个 */ r ...
将一个数字作为字符串打印的情况,数字是反序生成的:低位数字先于高位数字生成,但他们必须以与此相反的次序打印。 解决该问题有两种方法,一种是将生成的各个数字依次存储在字符数组中,然后再以相反的次序打印,这种方式与3.6中的itoa函数的处理方式相似。   另一种方法则是使用递归: #include<stdio.h> void printd(int n) { if(n<0){ putchar('-'); n=-n; } if(n/10) printd(n/10); putchar(n%10+'0'); }  
http://zhidao.baidu.com/question/42163882.html?fr=ala0   C语言中对变量的说明包括两方面的内容:变量类型以及变量的存储类型。变量类型如:int(整形),char(字符型)是用来说明变量所占用的内存空间的大小。变量存储类型用来说明 ...
http://hi.baidu.com/%C3%E2%B7%D1%B4%F3%BB%B0%D0%F2%C1%D0%BA%C5/blog/item/e3b2e4cb4f2be1f453664f06.html     对外部变量的说明和定义不是一回事.对外部变量的说明,只是声明该变量是在外部定义过的一个全局变量..在这里引用.而对外部变量的定义,则是要分配存储单元.一个全局变量只能定义一次,却可以多次引用. 用extern声明外部变量,目的是可以在其它的文件中调用.具体使用见下面的例子:     file1.c                                         ...
http://hi.baidu.com/%C3%E2%B7%D1%B4%F3%BB%B0%D0%F2%C1%D0%BA%C5/blog/item/2d559ddc8f07e2a8cd11661d.html   变量可以在程序中三个地方说明: 函数内部、函数的参数定义中或所有的函数外部。根据所定义位置的不同, 变量可分为局部变量、形式参数和全程变量。从空间角度来看,变量可以分为全局变量和局部变量,而从时间角度来分的 可以有静态存储变量和动态存储变量之分。   一。全局变量和局部变量 1。局部变量 他是 指在函数内部定义的变量 作用域为定义局部变量的函数 也就是说他只能在定义他的函数中使 ...
在头文件中声明函数时,前面的extern可有可无,只要这些函数曾在某个.c文件中实现就行了,不过一些函数没有在所包含的头文件中给出声明,同时函数的定义位于其它文件中,这时候使用该函数的.c文件必须用extern标记该函数为外部函数。举个例子:   /* c.h */ extern int max(int a, int b); extern int min(int a, int b); /* a.c */ #include <stdio.h> /* 这里需要明确指定output为extern函数 */ extern void output(); int max(i ...
#include <stdio.h> int buf = EOF; /* buffer for ungetch */ int getch(void) /* get a (possibly pushed back) character */ { int temp; if (buf != EOF) { temp = buf; buf = EOF; } else { temp = getchar(); } return temp; } vo ...
#include<stdio.h> #include<string.h> #define BUFSIZE 100 char buf[BUFSIZE]; int bufp = 0; int getch(void); void unGetch(int); /* Getch: get a ( possibly pushed back) character. */ int getch(void) { return (bufp > 0) ? buf[--bufp]: getchar(); } /* ...
#include<stdlib.h> #include<stdio.h> #include<ctype.h> #include<math.h> #include<string.h> #define MAXOP 100 #define TRUE 1 #define FALSE 0 #define MAX_ID_LEN 32 #define MAXVARS 30 #define NUMBER 0 /* 4-6 these are new for this ex ...
#include<stdlib.h> #include<stdio.h> #include<ctype.h> #include<math.h> #include<string.h> #define MAXOP 100 #define TRUE 1 #define FALSE 0 #define NUMBER 0 #define IDENTIFIER 1 int Getop(char s[]); void push(double val); double po ...
#include<stdlib.h> #include<stdio.h> #include<ctype.h> #include<math.h> #define MAXOP 100 #define NUMBER 0 #define TRUE 1 #define FALSE 0 int Getop(char s[]); void push(double val); double pop(void); void showTop(void); void duplicate(void); voi ...
在该程序中加入了取模(%)运算符,并对负数进行处理   #include <stdio.h> #include <stdlib.h> /* for atof() */ #include <ctype.h> #define MAXOP 100 /* max size of operand or operator */ #define NUMBER '0' /* signal that a number was found */ #define MAXVAL 100 /* maximum depth of val stac ...
4-2  对atof函数进行扩充,使它可以处理123.45e-6的科学表示法。其中,浮点数后面可能会紧跟一个e或者E以及一个指数(可能有正负号)   #include <ctype.h> #include <stdio.h> #define MAXLINE 100 int getline(char line[], int max); double atof(char s[]) { int i; double val; double power; int sign;//用于标记+ - 号 int flag=-1;//标记指数的正负 ...
Global site tag (gtag.js) - Google Analytics