第一百零一套:
101.1:找出各位数字上的和为特定值的数
int fun(int x)
{
int n, s1, s2, s3, t;
n=0;
t=100;
/**********found**********/
while(t<=999){
/**********found**********/
s1=t%10; s2=(t/10)%10; s3=t/100;
/**********found**********/
if(s1+s2+s3==x)
{ printf("%d ",t);
n++;
}
t++;
}
return n;
}
101.2:取出偶数位上的数组成新数
void fun (long s, long *t)
{
long sl=10;
s /= 10;
*t = s % 10;
/************found************/
while ( s > 0)
{ s = s/100;
*t = s%10*sl + *t;
sl = sl * 10;
}
}
101.3:降序排序
typedef struct
{ char num[10];
int s;
} STREC;
void fun( STREC a[] )
{
int i,j;
STREC t;
for(i=0;i<N;i++)
for(j=i+1;j<N;j++)
if(a[i].s<a[j].s)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
第一百零二套:
102.1:修改学生数据
struct student {
long sno;
char name[10];
float score[3];
};
void fun( struct student *b)
{
/**********found**********/
b->sno = 10004;
/**********found**********/
strcpy(b->name , "LiJie");
}
102.2:计算数学公式(递归)
double fun(double a, double x0)
{
double x1, y;
x1=(x0+ a/x0)/2.0;
/**********found**********/
if( fabs(x1-x0)>=0.00001 )//>=&&>
y=fun(a,x1);
else y=x1;
return y;
}
102.3:找出特定的数据
typedef struct
{ char num[10];
double s;
} STREC;
double fun( STREC *a, STREC *b, int *n )
{
int i,j=0;
double av=0.0;
for(i=0;i<N;i++)
av+=a[i].s/N;
for(i=0;i<N;i++)
if(a[i].s>=av)
b[j++]=a[i];
*n=j;
return av;
}
第一百零三套:
103.1:删除单链表中的重复值
typedef struct list
{ int data;
struct list *next;
} SLIST;
void fun( SLIST *h)
{
SLIST *p, *q;
p=h->next;
if (p!=NULL)
{ q=p->next;
while(q!=NULL)
{ if (p->data==q->data)
{ p->next=q->next;
/**********found**********/
free(q);
/**********found**********/
q=p->next;
}
else
{ p=q;
/**********found**********/
q=q->next;
}
}
}
}
103.2:升序数组(选择法)
void fun(int a[], int n)
{
int i, j, t, p;
for (j = 0 ;j < n-1 ;j++) {
/************found************/
p = j;
for (i = j;i < n; i++)
if(a[i] < a[p])
/************found************/
p = i;
t = a[p] ; a[p] = a[j] ; a[j] = t;
}
}
103.3:在数组中找出特定数
void fun ( int m, int *a , int *n )
{
int i,j=0;
for(i=1;i<=m;i++)
if((i%7==0)||(i%11==0))
a[j++]=i;
*n=j;
}
第一百零四套:
104.1:按要求变换矩阵的值
#define N 4
/**********found**********/
void fun(int (*t)[N] )
{
int i, j;
for(i=1; i<N; i++)
{ for(j=0; j<i; j++)
{
/**********found**********/
t[i][j] =t[i][j]+t[j][i];
/**********found**********/
t[j][i] =0;
}
}
}
104.2:计算数学公式
#define FU(m,n) (m)/(n)//宏定义的要点
float fun(float a,float b,float c)
{ float value;
value=FU(a+b,a-b)+FU(c+b,c-b);
/************found************/
return(value);
}
104.3:删除前导*—串的经典问题8.0
void fun( char *a )
{
char *t=a;
while(*t=='*')
{
t++;
}
while(*t)
{
*a=*t;
a++;
t++;
}
*a='\0';
}
第一百零五套:
105.1:修改指定学生成绩
typedef struct student {
long sno;
char name[10];
float score[3];
} STU;
void fun(char *filename, long sno)
{
FILE *fp;
STU n; int i;
fp = fopen(filename,"rb+");
/**********found**********/
while (!feof(fp))
{ fread(&n, sizeof(STU), 1, fp);
/**********found**********/
if (n.sno==sno) break;
}
if (!feof(fp))
{ for (i=0; i<3; i++) n.score[i] += 3;
/**********found**********/
fseek(fp, -(long)sizeof(STU), SEEK_CUR);
fwrite(&n, sizeof(STU), 1, fp);
}
fclose(fp);
}
105.2:插入排序
void insert(char *aa)
{
int i,j,n; char ch;
/**********found**********/
n=strlen( aa );
for( i=1; i<n ;i++ ) {
/**********found**********/
ch=aa[i];
j=i-1;
while ((j>=0) && ( ch<aa[j] ))
{ aa[j+1]=aa[j];
j--;
}
aa[j+1]=ch;
}
}
105.3:—找出最高分(链表)—
double fun( STREC *h )
{
int i;
double max=h->s;
while(h!=NULL)
{
if(max<h->s)
max=h->s;
h=h->next ;
}
return max;
}
第一百零六套:
106.1:—统计正负整数—
void fun( int *px, int *py)
{
/**********found**********/
int a=0,b=0,k ;
scanf( "%d", &k );
/**********found**********/
while (k!=0)
{ if (k>0 ) a++;
if(k<0 ) b++;
/**********found**********/
scanf( "%d", &k );
}
*px=a; *py=b;
}
106.2:累加链表数据
typedef struct list
{ int data;
struct list *next;
} LIST;
int fun(LIST *h)
{
LIST *p;
/**********found**********/
int t=0;
p=h;
/**********found**********/
while( p )
{
/**********found**********/
t=t+p->data;
p=(*p).next;
}
return t;
}
106,3—:统计特定字母的个数—
void fun( char (*t)[M], int *a ,int *c)
{
int i,j;
*a=*c=0;
for(i=0;i<M;i++)
for(j=0;j<M;j++)
{
if(t[i][j]=='A')
(*a)++;//*a++&&(*a)++
if(t[i][j]=='C')
(*c)++;
}
}
第一百零七套:
107.1:—闰年判断—
int isleap(int year)
{
int leap;
leap= (year%4==0 && year%100!=0 || year%400==0);
/**********found**********/
return leap;
}
int fun(int year, int month, int day)
{
int table[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int days=0 , i;
for(i=1; i<month; i++)
days=days + table[i];
/**********found**********/
days=days+day ;
if( isleap(year) && month>2 )
/**********found**********/
days=days+1;
return days;
}
107.2:计算课程平均分
typedef struct
{ char num[8];
double score[2];
}STU ;
double fun(STU std[], int n)
{
int i;
/**********found**********/
double sum=0.0 ;
/**********found**********/
for(i=0; i<n ; i++)
/**********found**********/
sum += std[i].score[0];
return sum/n;
}
107.3:判断整数位数
int fun(int n)
{
int bits=0;
while(n)
{
bits++;
n/=10;
}
return bits;
}
第一百零八套:
108.1:查找不合格学生
typedef struct
{ char num[8];
double score[2];
/**********found**********/
} STU ;
int fun(STU std[ ], int n)
{
int i, k=0;
for(i=0; i<n; i++)
/**********found**********/
if( std[i].score[0]<60||std[i].score[1]<60 )
{ k++; printf("学号:%s ",std[i].num); }
/**********found**********/
return k ;
}
108.2:—完数判断—
int fun(int n, int a[], int *k)
{
int m=0, i, t;
t = n;
/**********found**********/
for( i=1; i<n; i++ )
if(n%i==0)//i不能是0;
{ a[m]=i; m++; t=t - i; }
/**********found**********/
*k=m;
/**********found**********/
if ( t==0 ) return 1;
else return 0;
}
108.3:找出MAX&&min
void fun(int *a, int *b, int *c, int *d)
{
int max,min;
max=min=*a;
if(max<*b)
max=*b;
if(min>*b)
min=*b;
if(max<*c)
max=*c;
if(min>*c)
min=*c;
if(max<*d)
max=*d;
if(min>*d)
min=*d;
*a=max;
*d=min;
}
第一百零九套:
109.1:交叉洗牌
void fun( int a[55], int n )
{
int i, k ;
/**********found**********/
int b[55];
for (i=0; i<n; i++)
{ for (k=1; k<= 27; k++)
{ b[ 2*k-1 ] = a[k];
/**********found**********/
b[ 2* k ] = a[k+27];
}
for (k=1; k<=54; k++)
/**********found**********/
a[k]=b[k];
}
}
109.2: —升序分解—
void fun( int n )
{
int j, b, c, m, flag=0;
for (b=1; b<=n/2; b++) {
/**********found**********/
m = n;
c = b;
while (m !=0 && m>=c) {
/**********found**********/
m = m - c; c++;
}
/**********found**********/
if (m==0)//注意这里!
{ printf("%d=", n);
for (j=b; j<c-1; j++) printf( "%d+", j );
printf("%d\n", j);
flag=1;
}
}
if(flag==0)
printf("不能分解\n");
}
109.3:—判断连续递增字符串—
int fun( char *t )
{
int flag=1,i;
char before_ch=t[0];
char current_ch;
int s=strlen(t);
while(s<2)
{
return 0;
}
for(i=1;t[i]!='\0';i++)
{
current_ch=t[i];
if(current_ch!=before_ch+1)
{
flag=0;
break;
}
before_ch=current_ch;
}
return flag;
}
第一百一十套:
110.1:变换数组元素
void fun(int *dt,int n)
{
int i,m,t;
/**********************found***********************/
m=0 ;
for(i=1;i<n;i++)
/**********************found***********************/
if(dt[i]<dt[m])
m=i;
t=dt[0];
/**********************found***********************/
dt[0]=dt[m];
dt[m]=t;
}
110.2:按要求返回值(本题修改的是主体函数并非功能函数)
void a( )
{
char ch;
int sort;
printf("本程序判断你从键盘上键入字符的种类,请输入字符(串):\n");
do
{
ch=getchar();
if(ch!='\n')
{
sort= my_isalpha( ch);
/**********************found***********************/
switch(sort)
{
case 1: printf("%c",'*'); break;
/**********************found***********************/
case -1: printf("%c",'#');break;
case 0: printf("%c",'?');
}
}
/**********************found***********************/
}while(ch !='\n');
printf("%c",'\n');
}
110.3:统计特定相连字母出现的次数
void fun(char*sp ,int *ct)
{
int i;
for(i=0;i<3;i++)
ct[i]=0;
for(i=0;sp[i]!='\0';i++)
{
if(sp[i]=='e'&&sp[i+1]=='a')
ct[0]++;
if(sp[i]=='o'&&sp[i+1]=='u')
ct[1]++;
if(sp[i]=='i'&&sp[i+1]=='u')
ct[2]++;
}
}