1.
#include <myhead.h>
void Bub_sort(int *arr,int n)//冒泡排序
{for(int i=1;i<n;i++){int count=0;for(int j=0;j<n-i;j++){if(arr[j]>arr[j+1]){int temp=arr[j];arr[j]=arr[j+1];arr[j+1]=temp;count++;}}if(count==0){break;}}printf("冒泡排序后输出结果:\n");for(int i=0;i<n;i++){printf("%d\n",arr[i]);}
}
void Sim_sort(int *arr,int n)//简单排序
{for(int i=0;i<n;i++){int maxi=i;for(int j=i+1;j<n;j++){if(arr[j]>arr[maxi]){maxi=j;}}if(maxi!=i){int temp=arr[maxi];arr[maxi]=arr[i];arr[i]=temp;}}printf("简单选择排序后输出结果:\n");for(int i=0;i<n;i++){printf("%d\n",arr[i]);}
}
void Output(int *arr,int n)
{printf("输出元素:");for(int i=0;i<n;i++){printf("arr[%d]=%d,",i,arr[i]);}printf("\n");
}
int main(int argc, const char *argv[])
{int n;puts("输入元素个数");scanf("%d",&n);int arr[n];for(int i=0;i<n;i++){printf("输入元素:");scanf(" %d",&arr[i]);}Output(arr,n);Bub_sort(arr,n);Sim_sort(arr,n);return 0;
}
2.
#include <myhead.h>
int Max(int m,int n,int arr[][n])//最大值
{int max=arr[0][0];for(int i=0;i<m;i++){for(int j=0;j<n;j++){if(max<arr[i][j]){max=arr[i][j];}}}return max;
}
int Min(int m,int n,int arr[][n])//最小值
{int min=arr[0][0];for(int i=0;i<m;i++){for(int j=0;j<n;j++){if(min>arr[i][j]){min=arr[i][j];}}}return min;
}int main(int argc, const char *argv[])
{int m,n;printf("行数:");scanf("%d",&m);printf("列数:");scanf("%d",&n);int arr[m][n];for(int i=0;i<m;i++){for(int j=0;j<n;j++){printf("输入arr[%d][%d]:",i,j);scanf("%d",&arr[i][j]);printf("\n");}}printf("max=%d,min=%d\n",Max(m,n,arr),Min(m,n,arr));return 0;
}
3+4
void Copy(char str1[],char str2[],int n)//拷贝
{for(int i=0;i<n;i++){str1[i]=str2[i];if(str2[i]=='\0'){break;}}
}
void Cmp(char str1[],char str2[])//比较
{int i=0;for(i;str1[i]==str2[i];i++){if(str1[i]=='\0'){break;}}int def=str1[i]-str2[i];if(def>0){printf("def=%d,s1>s2\n",def);}if(def<0){printf("def=%d,s1<s2\n",def);}if(def=0){printf("def=%d,s1=s2\n",def);}
}
int main(int argc, const char *argv[])
{char str1[20],str2[10];puts("输入字符串1:");gets(str1);puts("输入字符串2:");gets(str2);printf("字符串1:%s\n",str1);printf("字符串2:%s\n",str2);puts("输入命令:1.拷贝 2.比较");int m;scanf(" %d",&m);if(m==1){Copy(str1,str2,10);printf("字符串1:%s\n",str1);printf("字符串2:%s\n",str2);}if(m==2){Cmp(str1,str2);}return 0;
}
.