ITfeng

 

2012年5月8日

经典递归程序----反向输出字符串

摘要: #include<stdio.h>void reverse(char*s);int main(){char *a="hello world";reverse(a);}void reverse(char*s){if(*s=='\0')return ;reverse(s+1);printf("%c",*s);} 阅读全文

posted @ 2012-05-08 21:34 ITfeng 阅读(160) 评论(0) 推荐(0) 编辑

Linux---文件操作

摘要: 将1.txt中的数字读出来,再逆序输出到2.txt中去,要求逆序熟悉 fopen fclose fprintf,fscanf的用法#include<stdio.h>#include<stdlib.h>#define INCREASE 20int main(){int max=10;FILE*fp1;FILE*fp2;int *array=(int*)malloc(max*sizeof(int));int *temp;fp1=fopen("1.txt","r");if(fp1==NULL){printf("open 1.t 阅读全文

posted @ 2012-05-08 21:18 ITfeng 阅读(159) 评论(0) 推荐(0) 编辑

浮点数转成字符串

摘要: #include<stdio.h> #include<stdlib.h>char*func(double num,char str[]){int i,temp,j=0;temp=(int)num;//先取整数部分while(temp){str[j++]=temp%10+'0';temp/=10;}//注意数是逆序的 ,需要转换for(i=0;i<j/2;i++){temp=str[i];str[i]=str[j-i-1];str[j-i-1]=temp;} str[j++]='.';num-=(int)num;for(i=0;i&l 阅读全文

posted @ 2012-05-08 20:51 ITfeng 阅读(277) 评论(0) 推荐(0) 编辑

两个有序链表合成一个有序链表

摘要: #include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list*next;}List;List*hebin(List*head1,List*head2){List*head,*rear;if(head1==NULL)return head2;if(head2==NULL)return head1;if(head1->data<head2->data){rear=head=head1;head1=head1->next;}else{ rear=head=head 阅读全文

posted @ 2012-05-08 20:50 ITfeng 阅读(644) 评论(0) 推荐(0) 编辑

导航