#include "01head.h"
//一维数组输入
void Arr_input(int *arr,int len){
int i;
for(i=0;i<len;i++){
scanf("%d",(arr+i));
}
}
//一维数组输出
void Arr_ouput(int *arr,int len){
int i;
for(i=0;i<len;i++){
printf("%d ",*(arr+i));
}
putchar(10);
}
//冒泡排序
void Bubble_sort(int *arr,int len,int flag){
int i,j,temp;
for(i=0;i<len-1;i++){
for(j=0;j<len-i-1;j++){
if(1==flag){
if(*(arr+j)>*(arr+j+1)){
temp=*(arr+j);
*(arr+j)=*(arr+j+1);
*(arr+j+1)=temp;
}
}
if(0==flag){
if(*(arr+j)<*(arr+j+1)){
temp=*(arr+j);
*(arr+j)=*(arr+j+1);
*(arr+j+1)=temp;
}
}
}
}
}
//简单选择排序
void Simple_sort(int *arr,int len,int flag){
int i,j,value,temp;
for(i=0;i<len-1;i++){
value=i;
for(j=i+1;j<len;j++){
if(1==flag){
if(*(arr+value)>*(arr+j)){
value=j;
}
}
if(0==flag){
if(*(arr+value)<*(arr+j)){
value=j;
}
}
}
if(value!=i){
temp=*(arr+i);
*(arr+i)=*(arr+value);
*(arr+value)=temp;
}
}
}
//找最大值
int Max_value(int *arr,int len){
int i;
int max=*arr;
for(i=0;i<len;i++){
if(*(arr+i)>max){
max=*(arr+i);
}
}
return max;
}
//找第二大值
int Second_value(int *arr,int len){
int i,max_index=0,second=*arr;
int max=*arr;
for(i=0;i<len;i++){
if(*(arr+i)>max){
max_index=i;
}
}
for(i=0;i<len;i++){
if(i==max_index){
continue;
}
if(*(arr+i)>second){
*(arr+second)=*(arr+i);
}
}
return second;
}
//杨辉三角
//字符串逆置
void Str_inv(char *str){
int i,j=0;
char temp;
while(*(str+j)){
j++;
}
j--;
for(i=0;i<j;i++){
temp=*(str+i);
*(str+i)=*(str+j);
*(str+j)=temp;
j--;
}
}
//单词逆置
void Word_inv(char *str){
Str_inv(str);
int i,j,index;
char temp;
i=0;
index=0;
while(*(str+i)){
i=index;
while(*(str+i)==' '){
i++;
}
j=i;
while(*(str+j)!='\0'&&*(str+j)!=' '){
j++;
}
index=j;
j--;
for(i;i<j;i++){
temp=*(str+i);
*(str+i)=*(str+j);
*(str+j)=temp;
j--;
}
}
}
//删除空格
void Delete_space(char *str){
int i,j,count=0;
while(*(str+count)){
count++;
}
j=0;
for(i=0;i<count;i++){
if(*(str+i)!=' '){
*(str+j)=*(str+i);
j++;
}
}
*(str+j)='\0';
}
//计算字符串长度
int My_strlen(char *str){
int count=0;
while(*(str+count)){
count++;
}
return count;
}
//字符串拷贝
char *My_strcpy(char *dest,char *src){
int i,j;
i=0;
while(*(src+j)){
*(dest+i)=*(src+j);
i++;
j++;
}
*(dest+i)=*(src+j);
return dest;
}
//字符串追加
char *My_strcat(char *dest,char *src){
int i,j;
i=0;
while(*(dest+i)){
i++;
}
j=0;
while(*(src+j)){
*(dest+i)=*(src+j);
i++;
j++;
}
*(dest+i)=*(src+j);
return dest;
}
//字符串比较
int My_strcmp(char *s1,char *s2){
int i=0,ret;
while(*(s1+i)){
if(*(s1+i)!=*(s2+i)){
break;
}
}
return ret=*(s1+i)-*(s2+i);
}
//递归求各个位数之和
int func(int n){
if(0==n) return 0;
else {
return n%10+func(n/10);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
C语言基础汇总代码,多文件编译
共4个文件
c:2个
out:1个
h:1个
需积分: 0 2 下载量 131 浏览量
2024-03-10
14:30:32
上传
评论
收藏 6KB ZIP 举报
温馨提示
C语言基础汇总代码,多文件编译
资源推荐
资源详情
资源评论
收起资源包目录
01exam.zip (4个子文件)
01exam
01main.c 1KB
01exam.c 3KB
a.out 17KB
01head.h 857B
共 4 条
- 1
资源评论
weixin_44559978
- 粉丝: 129
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功