޸⣨һ
MODI1.Cй涨ַȫΪĸfunĹǣͳaַָÿĸַгֵĴͳʱִСдִߵĸжͬһɣ
ַdadbcdbabdbӦӦΪbd
funָλĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ
#include<stdio.h>
#include  <stdio.h>
#include  <string.h>
void fun(char  a[])
{  int  b[26], i, n,max;
   for (i=0; i<26; i++)
/**********found**********/
      a[i] = 0;
   n= strlen(a);
   for (i=0; i<n; i++)
      if (a[i] >='a' && a[i]<='z')
/**********found**********/
         b[a[i] - 'A']++;
      else  if (a[i] >='A' && a[i]<='Z')
         b[a[i] -'A']++;
   max = 0;
   for (i=1; i<26; i++)
/**********found**********/
     if (b[max] > b[i])
       max=i;
   printf("ִַ :  %c\n", max + 'a');
}
main( )
{  char  a[200];
   printf("һͳƵַ :   ");   scanf("%s", a);
   fun(a);
}

޸⣨
    дӼɸУ0벢һԪСикfunĹǣԪֵΪƽֵ(0)
    磺ԪеֵΪ3947,21,28,15,0нΪ19.250000
    еĴʹܵóȷĽ
    ע⣺лɾУҲøĳĽṹ
#include <stdio.h>
double fun ( int x[])
{
/************found************/
  int sum = 0.0;
  int c=0, i=0;
  while (x[i] != 0)
  { if (x[i] > 0) {
       sum += x[i]; c++; }
    i++;
  }
/************found************/
  sum \= c;
  return sum;
}
main( )
{  int x[1000];  int i=0;
   printf( "\nPlease enter some data (end with 0): " );
   do
     {  scanf("%d", &x[i]);  }
   while (x[i++] != 0);
   printf("%f\n", fun ( x ));
}

޸⣨
иУfunĹǣҳһڸmҽmΪֵء
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ
#include  <stdlib.h>
#include  <conio.h>
#include  <stdio.h>
int fun( int m)
{ int i,k;
  for (i=m+1; ;i++)
     { for (k=2;k<i;k++)
/*************found**************/
          if (i%k!=0)
           break;
/*************found**************/
        if (k<i)
         return(i);
     }
}
void main()
{  int n;
   system("CLS");
   printf("\nPlease enter n: ");
   scanf("%d",&n);
   printf ("%d\n",fun(n));
}

޸⣨ģ
икfunĹǣиλΪżȡһtСλڸλλڵλ
磬sеΪ87653142ʱtе8642
еĴʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ
#include <stdio.h>
void fun (long  s, long *t)
{ int   d;
  long  sl=1;
    *t = 0;
    while ( s > 0)
    {  d = s%10;
/************found************/
       if (d%2=0)
       {  *t=d* sl+ *t;
          sl *= 10;
       }
/************found************/
       s \= 10;
    }
}
main()
{  long s,t;
   printf("\nPlease enter s:"); scanf("%ld", &s);
   fun(s, &t);
   printf("The result is: %ld\n", t);
}

޸⣨壩
иĹǣһk(2k10000)(Ϊ)磬2310Ӧ2,3,5,7,11
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ
#include  <conio.h>
#include  <stdio.h>
/*************found**************/
IsPrime(int n);
{ 
  int i,m;
  m=1;
  for(i=2;i<n;i++)
 /*************found**************/
     	if!(n%i)
	{
		m=0;
		break;
	}

  return(m);
}
main()
{ 
  int j,k;
  printf("\nPlease enter an interger number between 2 and 10000: ");
  scanf("%d",&k);
  printf("\nThe prime factor(s) of %d is(are): ",k);
  for(j=2;j<k;j++)
 	if((!(k%j)) && (IsPrime(j)))
		printf("%4d,",j);
  printf("\n");
}

޸⣨
и,funĹǣsַָ,ҳtַָĸΪֵء,sַָеΪabcdabfab,tַָΪab,3
еĴ,ʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ
#include  <stdlib.h>
#include  <conio.h>
#include  <stdio.h>
#include  <string.h>
int fun (char  *s,  char  *t)
{int  n;  char *p, *r;
 n=0;
 while(*s)
   {p=s;
    r=t;
    while (*r)
/*************found**************/
      if(*r==*p)  {r++; p++}
       else  break;
/*************found**************/
       if(r=='\0')
         n++;
       s++;
   }
 return n;
}
void main( )
{char  s[100],  t[100];  int  m;
 system("CLS");
 printf("\nPlease enter string s: ");
 scanf("%s",s);
 printf("\nPlease enter substring t: ");
 scanf ("%s",t);
 m=fun(s,t);
 printf("\nThe result is: m=%d\n", m);
}

޸⣨ߣ
икfunĹǣ㺯F(x,y,z)(xy)/(xy)(zy)/(zy)ֵxyֵȣzyֵȡ
磬xֵΪ9yֵΪ11zֵΪ15ʱֵΪ-3.50
еĴʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/************found************/
#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);
}
main()
{  float  x,y,z,sum;
   printf("Input  x  y  z:  ");
   scanf("%f%f%f",&x,&y,&z);
   printf("x=%f,y=%f,z=%f\n",x,y,z);
   if (x==y||y==z){printf("Data error!\n");exit(0);}
   sum=fun(x,y,z);
   printf("The result is : %5.2f\n",sum);
}

޸⣨ˣ
икfunĹǣ1055֮䣬ܱ3һλϵֵ5ЩbָУЩĸΪֵء涨alŸλa2ʮλ
еĴʹܵóȷĽ
ע⣺лɾУҲøĵĳĽṹ
#include <stdio.h>
int fun( int  *b )
{  int   k,a1,a2,i=0;
   for(k=10; k<=55; k++) {
/************found************/
      a2=k/1O;
      a1=k-a2*10;
      if((k%3==0 && a2==5)||(k%3==0 && a1==5))
      {  b[i]=k; i++; }
   }
/************found************/
   return  k;
 }
main( )
{  int  a[100],k,m;
   m=fun( a );
   printf("The result is :\n");
   for(k=0; k<m; k++) printf("%4d",a[k]);  printf("\n");
}

޸⣨ţ
иУfunĹǣһַ(ȣ20)ַеַASCIIֵ磬"edcba"Ӧ"abcde"
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ
#include  <string.h>
#include  <stdio.h>
void fun(char  t[])
{
 char c;
 int i,j;
 /*************found**************/
 for(i=strlen(t);i;i--)
     for(j=0;j<i;j++)
        /*************found**************/
	  if(t[j]<t[j+1])
          {
           c= t[j];
           t[j]=t[j+1];
           t[j+1]=c;
          }
}
main()
{
 char  s[81];
 printf("\nPlease  enter a character string :");
 gets(s);
 printf("\nBefore sorting : %s\n",s);
 fun(s);
 printf("\nAfter sorting decendingly: %s\n",s);
}

޸⣨ʮ
икfunĹǣɾָpַָепհַ(Ʊسз)
ַʱ'#'롣
еĴʹȷĽ
ע⣺лɾУҲøĳĽṹ
#include <string.h>
#include <stdio.h>
#include <ctype.h>
fun ( char *p)
{  int i,t;  char c[80];
/************found************/
   For (i = 0,t = 0; p[i] ; i++)
      if(!isspace(*(p+i))) c[t++]=p[i];
/************found************/
   c[t]="\0";
   strcpy(p,c);
}

main( )
{  char c,s[80];
   int i=0;
   printf("Input a string:");
   c=getchar();
   while(c!='#')
   {  s[i]=c;i++;c=getchar(); }
   s[i]='\0';
   fun(s);
   puts(s);
}

޸⣨ʮһ
икfunĹǣm(1m10)ַһ´ptָ洢С磺"abc""CD""EF""abcCDEF"
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ
#include <stdio.h>
#include <string.h>
void  fun ( char  str[][10], int  m, char  *pt )
{
/************found************/
    Int  k, q, i ;
    for ( k = 0; k < m; k++ )
    {  q = strlen ( str [k] );
       for (i=0; i<q; i++)
/************found************/
       pt[i] = str[k,i] ;
       pt += q ;
       pt[0] = 0 ;
    }
}

main( )
{    int  m, h ;
     char s[10][10], p[120] ;
     printf( "\nPlease enter  m:" ) ;
     scanf("%d", &m) ;  gets(s[0]) ;
     printf( "\nPlease enter  %d string:\n", m ) ;
     for ( h = 0; h < m; h++ ) gets( s[h]) ;
     fun(s, m, p) ;
     printf( "\nThe result  is :  %s\n", p) ;
}

޸⣨ʮ
иУfunĹǣȡַеַγµַȡԭַ
funеĴʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void fun(char *s)
{int i,j;
 for(i=0,j=0; s[i]!= '\0'; i++)
     if(s[i]>= '0'&&s[i]<= '9')
/*************found**************/
        s[j]=s[i];
/*************found**************/
     s[j]=\0;
}
void main()
{char item[80];
 system("CLS");
 printf("\nEnter a string: ");gets(item);
 printf("\nThe string is:%s\n",item);
 fun(item);
 printf("\nThe string of changing is :%s\n",item);
}

޸⣨ʮ
NɵѷһάУикfunĹǣ۰ҷmеλáҵ±ֵ򣬷-1
۰ҵĻ㷨ǣÿβǰȷдķΧlowhigh(low<high)Ȼmмλ(mid)ԪصֵбȽϡmֵмλԪصֵһεĲҷΧмλ֮ԪУ֮һεĲҷΧмλ֮ǰԪСֱlow>highҽ
еĴʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ
#include <stdio.h>
#define  N  10
/************found************/
void fun(int  a[], int  m )
{  int  low=0,high=N-1,mid;
   while(low<=high)
   {  mid=(low+high)/2;
      if(m<a[mid])
        high=mid-1;
/************found************/
      else If(m > a[mid])
        low=mid+1;
      else  return(mid);
   }
   return(-1);
}
main()
{  int  i,a[N]={-3,4,7,9,13,45,67,89,100,180 },k,m;
   
   printf("aе:");
   for(i=0;i<N;i++) printf("%d ", a[i]);
   printf("Enter m: ");  scanf("%d",&m);
   k=fun(a,m);
   if(k>=0) printf("m=%d,index=%d\n",m,k);
   else  printf("Not be found!\n");
}

޸⣨ʮģ
иУfunĹǣNѧѧϰɼӸߵ͵˳ҳǰm(m10)ѧЩѧݴһ̬洢У˴洢׵ַΪֵء
еĴ,ʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ
#include  <stdlib.h>
#include  <conio.h>
#include  <string.h>
#include  <stdio.h>
#include  <malloc.h>
#define N 10
typedef struct ss
   { char num[10];
     int s;
   } STU;
STU *fun(STU a[], int m)
{ STU b[N],*t;
  int i, j,k;
/*************found**************/
  *t=calloc(m,sizeof(STU));
  for(i=0;i<N;i++) b[i]=a[i];
  for(k=0;k<m;k++)
     { for (i=j=0;i<N;i++)
          if(b[i].s>b[j].s) j=i;
/*************found**************/
      t[k].num=b[j].num;
      t[k].s=b[j].s;
      b[j].s=0;
     }
return t;
}
outresult(STU a[],FILE *pf)
{ int i;
  for(i=0;i<N;i++)
     fprintf(pf, "No=%s Mark=%d\n ",a[i].num, a[i].s);
  fprintf(pf, "\n\n ");
}
void main()
{ STU a[N]={{ "A01 ",81},{ "A02 ",89},{ "A03 ",66},{ "A04 ",87},{ "A05 ",77},
			{ "A06 ",90},{ "A07 ",79},{ "A08 ",61},{ "A09 ",80},{ "A10 ",71}};
  STU *pOrder;
  int i, m;
  system("CLS");
  printf("*****THE RESULT*****\n");
  outresult(a,stdout);
  printf("\nGive the number of the students who have better score: ");
  scanf("%d",&m);
  while(m>10)
      { printf("\nGive the number of the students who have better score: ");
  scanf("%d",&m);
}
  pOrder=fun(a,m);
  printf("***** THE RESULT*****\n");
  printf("The top :\n");
  for(i=0;i<m;i++)
     printf("%s  %d\n",pOrder[i].num, pOrder[i].s);
  free(pOrder);
}

޸⣨ʮ壩
MODI1.CУfunĹǣnѧ2ſγɼĽṹstdУ1ſγ̵ƽ֣Ϊֵء磬и4ѧݣеĽΪ1ſγ̵ƽǣ76.125000
funָλĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ
#include  <stdio.h>
typedef  struct
{  char  num[8];
  double  score[2];
}STU ;
double fun(STU  std[], int  n)
{  int   i;
/**********found**********/
   double  sum ;
/**********found**********/
   for(i=0; i<2 ; i++)
/**********found**********/
      sum += std[i].score[1]; 
   return  sum/n;
}
main()
{  STU  std[ ]={ "N1001", 76.5,82.0 ,"N1002", 66.5,73.0, 
              "N1005", 80.5,66.0,"N1006", 81.0,56.0 };
   printf("1ſγ̵ƽǣ%lf\n", fun(std,4) );
}

޸⣨ʮ
икfunĹǣMM,ȻԽԪ֮,Ϊֵء
еĴ,ʹܵóȷĽ
ע⣺лɾУҲøĳĽṹ

#include <stdio.h>
#define M 5
/************found************/
int fun(int n, int xx[][])
{  int  i, j, sum=0;
  printf( "\nThe %d x %d matrix:\n", M, M );
  for(i = 0; i < M; i++)
  {  for(j = 0; j < M; j++)
/************found************/
      printf("%f ", xx[i][j]);
    printf("\n");
  }
  for(i = 0 ; i < n ; i++)
    sum += xx[i][i]+xx[i][ n-i-1 ];
  return( sum );
}
main( )
{  int aa[M][M]={{1,2,3,4,5},{4,3,2,1,0},
   {6,7,8,9,0},{9,8,7,6,5},{3,4,5,6,7}};
   printf("\nThe sum of all elements on 2 diagnals is %d.",fun(M, aa));
}

޸⣨ʮߣ
иУfunĹǣnĽ׳ˡ
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ

#include <stdlib.h>
#include <stdio.h>
double fun(int n)
{
	double result=1.0;
	while(n>1 && n<170) 
/*************found**************/
      Result *=--n;
/*************found**************/
	return;
}
void main()
{
	int n;
	printf("Enter an integer: ");
	scanf("%d",&n);
	printf("\n%d!=%1g\n ",n,fun(n));
}

޸⣨ʮˣ
иУfunĹǣ߳(ֵ)жܷ񹹳ΡܹɵȱΣ򷵻3ǵΣ򷵻2ܹ򷵻1ܣ򷵻0
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ

#include <stdio.h>
#include <math.h>
int fun(int a,int b,int c)
{ if(a+b>c&&b+c>a&&a+c>b)
     {if(a==b && b==c) 
/*************found**************/
       return 1;
      else if(a==b||b==c||a==c)
       return 2;
/*************found**************/
      else return 3;
     }
  else return 0;
}
void main()
{ 
	int a,b,c,shape;
    printf("\nInput a,b,c: "); 
    scanf("%d%d%d",&a,&b,&c);
    printf("\na=%d, b=%d, c=%d\n",a,b,c);
    shape=fun(a,b,c);
    printf("\nThe shape :%d\n",shape);
}

޸⣨ʮţ
иĳУfunĹǣ㲢k10ܱ1317Ȼ֮͡kֵ룬kֵΪ500ֵΪ4622
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int fun(int k)
{ int m=0,mc=0, j;
  while((k>=2) && (mc<10))
  {
/*************found**************/
	  if((k%13=0)||(k%17=0))
	  { m=m+k;mc++; }
      k--;
/*************found**************/
	  return m;
}
void main()
{
	printf("%d\n ",fun(500));
}

޸⣨ʮ
кfunĹǣȰbַָеַţȻaַָеַbַָеַе˳򽻲ϲcָУʣַcָβ
磬aַָеΪ"abcdefg"bַָеΪ"1234"ʱcָеӦΪ"a4b3c2d1efg"aַָеΪ"1234"bַָΪ"abcdefg"ʱcָеӦΪ"1g2f3e4dcba"
еĴʹܵóȷĽ
ע⣺ҪĶmainлɾУҲøĳĽṹ

#include <stdio.h>
#include <string.h>
void fun(char *a,char *b,char *c)
{
	int i,j;char ch;
	i=0; j=strlen(b)-1;
/************found************/
	while(i > j)
	{
		ch=b[i]; b[i]=b[j]; b[j]=ch;
		i++; j--;
	}
	while ( *a || *b ) 
	{
/************found************/
	 If ( *a )
	 { *c = *a;  c++; a++; }
	 if ( *b )
	 { *c = *b;  c++; b++; }
	}
	*c = 0;
}
main()
{
   char s1[100],s2[100],t[200];
   printf("\nEnter s1 string : ");
   scanf("%s",s1);
   printf("\nEnter s2 string : ");
   scanf("%s",s2);
   fun( s1, s2, t );
   printf("\nThe result is : %s\n",t);
}




















