// 111.c
#include<stdio.h>
void fun(char a[],char x)
{
char *p=a,t;
while(*a)a++;
*(a+1)=0;
*a=x;
while(a>p)
{
if(*a<*(a-1)){t=*a;*a=*(a-1);*(a-1)=t;}
a--;
}
}
void main()
{
char a[20]="134689",b[]="22334744";
int i=0;
while(b[i])
{
fun(a,b[i]);
i++;
}
puts(a);
getch();
}
// 112.c
#include<stdio.h>
void main()
{
char a[]="this is a book ";
int num=0,i;
i=0;
while(a[i])
{
while(a[i]==' '&&a[i])i++;
if(a[i]!='\0')num++;
while(a[i]!=' '&&a[i])i++;
}
printf("%d",num);
getch();
}
// 113.c
#include<stdio.h>
void main()
{
char a[]="this is a book this is a book ";
int num=0,i,flag=0;
i=0;
while(a[i])
{
if(a[i]==' ')flag=0;
else if(flag==0)
{
num++;
flag=1;
}
i++;
}
printf("%d",num);
getch();
}
// 114.c
#include<stdio.h>
void main()
{
char a[][20]={"guanyu","zhangfei","zhaoyun"},tt[20];
int b[]={99,97,98},i,j,t;
for(i=0;i<2;i++)
for(j=i+1;j<3;j++)
if(b[i]<b[j])
{
t=b[i];b[i]=b[j];b[j]=t;
strcpy(tt,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],tt);
}
for(i=0;i<3;i++)
printf("%s:%d\n",a[i],b[i]);
getch();
}
// 115.c
#include<stdio.h>
void main()
{
char a[][20]={"guanyu","zhangfei","zhaoyun"},max[20];
int i;
strcpy(max,a[0]);
for(i=1;i<3;i++)
if(strcmp(max,a[i])<0)
strcpy(max,a[i]);
printf("%s",max);
getch();
}
// 116.c
#include<stdio.h>
void main()
{
int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
i,x;
scanf("%d",&x);
i=0;
while(i<15)
{
if(x==a[i])break;
i++;
}
if(i==15)printf("sorry not find");
else printf("%d",i+1);
getch();
}
// 117.c
#include<stdio.h>
int fun(int a[],int x)
{
int min,mid,max,n=0;
min=0;max=14;mid=(min+max)/2;
while(a[mid]!=x)
{
if(x<a[mid])max=mid-1;
else min=mid+1;
mid=(min+max)/2;
n++;
if(n>15)return 0;
}
return mid+1;
}
void main()
{
int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
m,x;
scanf("%d",&x);
m=fun(a,x);
if(m>0)printf("%d",m);
else printf("not found");
getch();
}
// 118.c
#include<stdio.h>
int fun1(char a[],char b[])
{
while(*b==*a&&*b){a++;b++;}
if(*b==0)return 1;
return 0;
}
int fun(char a[],char b[])
{
int num=0;
while(*a)
{
if(fun1(a,b)==1)num++;
a++;
}
return num;
}
void main()
{
char a[]="this is a book";
printf("%d",fun(a,"is"));
getch();
}
// 119.c
#include<stdio.h>
void main()
{
int i,s=0;
char m;
for(i=0;i<4;i++)
{
s=0;
m=i+65;
if(m!='A')s++;
if(m=='C')s++;
if(m=='D')s++;
if(m!='D')s++;
if(s==3)break;
}
printf("%c",m);
getch();
}
// 120.c
#include<stdio.h>
int fun()//不带形参的函数
{
return 2;//正确的。
}
void fun()//没有确切的返回值
{
return 1;
}
fun()//函数不带返回类型,那么它就是int型
{
}
float fun()//函数返回值要以float为准
{
return 1;
}
网友评论