c语言
1.
#include <stdio.h>
#include "poi.c"
int main (void){
int i;
int a[5];
for(i=0;i<5;i++){
printf("请输入第%d个数",i+1);
scanf("%d",&a[i]);
}
paiXu(a);
}
2.
#include<stdio.h>
#include"poi.c"
int main (void){
char a[100];
char b[100];
printf("请输入第一个数组:");
scanf("%s",&a) ;
printf("请输入第二个数组:");
scanf("%s",&b) ;
int c=compare(a,b);
printf("%d",c);
}
3.
#include<stdio.h>
#include"poi.c"
int main (void){
char a[]="sdufusdhffndksfnjkdfdjsfdfbnsd,nfjkahfubjdsbugdsafdudihfk";
int c=changDu(a);
printf("%d",c+1);
}
4.它们用同以类库
#include<stdio.h>
#include<stdlib.h>
void paiXu(int a[5]){
int i,j,num;
int temp;
for(i=0;i>=0;i++) {
printf("\n请选择:1.升序 2.降序 3.退出");
scanf("%d",&num);
switch(num){
case 1:{
for(i=0;i<5;i++){
for(j=i+1;j<5;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<5;i++){
printf("%10d",a[i]) ;
}
break;
}
case 2:{
for(i=0;i<5;i++){
for(j=i+1;j<5;j++){
if(a[i]<a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<5;i++){
printf("%10d",a[i]) ;
}
break;
}
case 3:printf("退出中...");exit(0);
default:printf("\n失败,请重新选择!....");continue;
}
}
}
int compare(char a[],char b[]){
int aChangDu=0,bChangDu=0,ChangDu;
while(a[aChangDu]!='\0'){
aChangDu++;
}
while(b[bChangDu]!='\0'){
bChangDu++;
}
if(aChangDu>bChangDu){
ChangDu=bChangDu;
}else{
ChangDu=aChangDu;
}
int i;
for(i=0;i<ChangDu;i++){
if((int)a[i]>(int)b[i]){
return 1;
// break;
}else{
if((int)a[i]==(int)b[i]){
continue;
}else{
return -1;
}
}
}
if(aChangDu>bChangDu){
return 1;
}else{
if(aChangDu==bChangDu){
return 0;
}else{
return -1;
}
}
}
int changDu(char a[]){
int i=0;
while(a[i]!='\0'){
i++;
}
return i;
}