#include <stdio.h>
#include <conio.h>
void fun(char *a,char *h,char *p)
{char b[81],*x;
int i=0,j=0;
x=a;
  while (x<h) {b[j]=*x;x++;j++;}
  while (h<=p)
  if (*h!='*') {b[j]=*h;j++;h++;}
  else h++;
  p++;
  while (*p)  {b[j]=*p;j++;p++;}
  b[j]='\0';j=0;
  while (b[j])
  { a[i]=b[j];i++;j++;}
  a[i]='\0';
}
main()
{  char s[81],*t,*f;
    printf("Enter a string:\n");gets(s);
    t=f=s;
    while(*t) t++;
    t--;
    while (*t=='*') t--;
    while (*f=='*') f++;
    fun(s,f,t);
    printf("The string after deleted:\n");puts(s);
    NONO();
}
2
#include <stdio.h>
#include <math.h>
double  fun ( double  eps)
{
  int n=0;
  double down=1,up=1;
  double one ,pi=0;
  one  = (double)up/(double)down;
  while(one>=eps) {
      pi+=one;
      n++;
      up=up*n;
      down=down*(2*n+1);
      one=(double)up/(double)down;
  }
return pi*2;
}
main( )
{ double  x;
  printf("Input eps:") ;
  scanf("%lf",&x); printf("\neps = %lf, PI=%lf\n", x, fun(x));
  NONO();
}
3
#include <stdio.h>
char  *fun ( char *s,  char *t)
{
  int first=0,second=0;
  char *p,*q;
    p=s;
    q=t;
  while(*p++!='\0')
    first++;
  while(*q++!='\0')
    second++;
  if(first==second)
    return s;
  else if (first>second)
      return s;
  else
    return t; 
}
main( )
{ char a[20],b[10];
  printf("Input 1th string:") ;
  gets( a);
  printf("Input 2th string:") ;
  gets( b);
  printf("%s\n",fun (a, b ));
  NONO ();
}
4
#include <stdio.h>
#include <conio.h>
void fun(char *a,int n)
{ char b[81];
  int i=0,j=0,s=0,k;
  while (a[i]=='*') {s++;i++;}
  if (s>n)
  {  for (k=0;k<n;k++)
      {b[j]='*';j++;}
      while (a[i])
    {b[j]=a[i];j++;i++;}
      b[j]='\0'; i=0;j=0;
      while (b[j])
      { a[i]=b[j];i++;j++;}
      a[i]='\0';
  }
}
main()
{  char s[81];int n;
    printf("Enter a string:\n");gets(s);
    printf("Enter n:  ");scanf("%d",&n);
    fun(s,n);
    printf("The string after deleted:\n");puts(s);
    NONO();
}
5
#include <stdio.h>
float  fun ( float  *a ,  int  n )
{
  int i;
  float average;
  double sum=0;
  for(i=0;i<n;i++)
      sum+=a[i];
  average=(float)sum/n;
  return average;
}
main()
{ float score[30]={90.5, 72, 80, 61.5, 55}, aver;
  aver = fun( score, 5 );
  printf( "\nAverage score  is: %5.2f\n", aver);
  NONO ( );
}
6
#include <stdio.h>
#define N 8
typedef struct
{  char num[10];
    double s[N];
    double ave;
}STREC;
void fun(STREC *p)
{ int i;
  double aver=0;         
  for (i=0;i<N;i++)
  {aver=aver+(*p).s[i]; }
  (*p).ave=aver/N;
}
main()
{  STREC s={"GA005",85.5,76,69.5,85,91,72,64.5,87.5};
    int i;
    fun(&s);
    printf("The %s's student data:\n",s.num);
    for(i=0;i<N;i++)
      printf("%4.1f\n",s.s[i]);
    printf("\nave=%7.3f\n",s.ave);
    NONO();
}
7
#include <stdio.h>
#define N 12
typedef struct
{  char num[10];
    double s;
} STREC;
double fun(STREC *a,STREC *b,int *n)
{ int i,j;
  double aver=0;
  *n=0;
  for (i=0;i<N;i++)
  aver=aver+a[i].s;
  aver=aver/N;
  for (i=0;i<N;i++)
  if (a[i].s>=aver)
  {b[*n].s=a[i].s;
    for (j=0;j<10;j++)
      b[*n].num[j]=a[i].num[j];
    *n=*n+1;
  }
  return (aver);
}
main()
{  STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},{"GA09",60},{"GA11",79},{"GA12",73},{"GA10",90}};
计算机二级c语言选择题库  STREC h[N];FILE *out;
  int i,n;double ave;
  ave=fun(s,h,&n);
  printf("The %d student data which is higher than %7.3f:\n",n,ave);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。