正文

C语言试题及答案2007-06-10 11:25:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/redstar/26608.html

分享到:

一、改错题
1.随机输入10个数,选出其中最小数。程序如下:
main()
{int i,min,a[10];
printf("input 10 numbers:\n");
for(i=0;i<=10;i++)                       /*$ERROR1$*/for(i=0;i<10;i++) or for(i=0;i<=9;i++)
scanf("%d",a[i]);                          /*$ERROR2$*/ scanf("%d",&a[i]);
min=a[0];
for(i=1;i<10;i++)
if(a[i]<min) min=a[i];
printf("minnum=%d\n",min);
}
2.不用strcat函数,将键盘输入的两个字符串连接起来形成一个新串。
main()
{char s1[50],s2[20];
int I,j=0;
printf("Enter string No.1:\n");  gets(s1);
printf("Enter string No.2:\n");
scanf("%s",&s2);                                /*$ERROR1$*/scanf("%s",s2);
for(i=0;s1[i]!=0;i++);                             /*$ERROR2$*/ for(i=0;s1[i]!='\0';i++)
while((s1[i++]= =s2[j])!='\0');                 /*$ERROR3$*/while((s1[i++]=s2[j++])!='\0')
printf("\n New string:%s\n",s1);
}
3.下列程序的功能是:根据整型形参n,计算如下公式的值A1=1,A2=1/(1+A1),A3=1/(1+A2)……,An=1/(1+An-1)例如:若n=10,则输出A10为0.617977。
#include "stdio.h"
int fun(int n)                         /*$ERROR1$*/float fun(int n)
{float a=0;                           /*$ERROR2$*/float a=1;
int i;
for(i=2;i<=n;i++)  a=1/(1+a);
return a;
}
main()
{int n;
printf("\n Please Enter a value of n");  scanf("%d",&n);
printf("A%d=%f\n",n,fun);               /*$ERROR3$*/ printf("A%d=%f\n",n,fun(n));}
4.让计算机出10道100以内的整数加法题,让学生回答。回答正确时,计算机提示"正确",错误时提示"错误",并统计做对的题数。程序如下:
#include <stdio.h>
main()
{int a,b,c,i,n=0;
radomize();
for(i=0;i<10;i++)
{a=random(100);
b=random(100);
printf("%4d\n",a); printf("%c%3d\n",'+',b);  printf("=\n");  printf("?");
scanf("%d",c);                                  /*$ERROR1$*/ scanf("%d",&c);
if(c=a+b)                                     /*$ERROR2$*/ if(c= =a+b)
{printf("right\n"); n=n+1;}
else printf("wrong\n");}
printf("Right Total=%d!",n);
}  
5.下面程序的功能是输出字符串.
 Main()
 {char *a[]={English","Chinese","American",French"};
char**p;
int j=0;
p=a;
for(;j<=4;j++)                      /*$ERROR1$*/for(;j<4;j++)||for(;j<=3;j++)
||for(;j<4;j=j+1)||for(;j<=3;j=j+1)
printf("%s\n",*p); /*$ERROR2$*/  printf("%s\n",*p++); 或{printf(%s\n",*p);p++;}
}
6.下面程序先打印所给的前三个字符串,然后再打印前三个字符串的首字符.请找出程序中的错误.
Main()
{char alpha[5]={"a","bc","def","1","23"},**p;     /*$ERROR1$*/
/*char *alpha[5]= {"a","bc","def","1","123"},**p;*/
int i;  p=alpha;
for(i=0;i<3;i++,p++)
  printf("%s",**p);                        /*$ERROR2$*/ printf("%s",*p);
printf("\t"); p=p-3;
for(i=0;i<3;i++,p++)
  printf(%c\t,*p);                          /*$ERROR3$*/ printf("%c\t",**p);
printf("\n");
}
7.以下程序分别在a数组和b数组中放入an+1和bn+1个由小到大的有序数,程序把两个数组中的数按由小到大的顺序归并到c数组中.
#include<stdio.h>
main()
{int a[10]={1,2,5,8,9,10},an=5;  int b[10]={1,3,4,8,12,18},bn=5;
int i,j,c[20],max=9999;
a[an]=b[bn]=max;                   /*$ERROR1$*/ a[an+1]=b[bn+1]=max;
i=j=k=0;
While((a[i]!=max&&b[j]!=max))     /*$ERROR2$*/ while((a[i]!=max)||(b[j]!=max))
  if(a[i]<b[j]) {c[k]=a[i];k++;i++}
   Else{c[k]=b[k];k++;j++}        /*$ERROR3$*/ else{c[k]=b[j];k++;j++;}
For(i=0;i<k;i++;)
  Printf("%4d",c[i]);
Printf("\n");}
8. 以下程序是将输入的十进制数转换为二进制数输出.
 #include<stdio.h>
main()
{int y,i=0,j,a[16];
scanf("%d",&y);
do
{a[i]=y%2;
a[i++]=y/2;                                /*$ERROR1$*/a[i++]=y%2;
y/=2;
} while(y>=0);                              /*$ERROR2$*/while(y)或while(y>0)
for(j=i;j>=0;j--)                             /*$ERROR3$*/ for(j=i-1;j>=0;j--)
  printf("%d",a[j]);
printf("\n");
}

9. 以下程序判断输入的字符串是否是" 回文"(即顺读和倒读都一样,例如:LEVEL).
#include<stdio.h>
#include<string.h>
main()
{char s[81];  int i,j,n;
get(s);  n=strlen(s);
i=0;
j=n;                                            /*$ERROR1$*/j=n-1;
While(s[i]= =' ')i++;
While(s[j]= =' ')j--;
While(i<j||s[i]= =s[j] )                       /*$ERROR2$*/while(i<j&&s[i]= =s[j])
 {i++;j--;}
if(i>j) printf(No\n");                           /*$ERROR3$*/ if(i<j) printf("No\n);
else printf("Yes\n);
}
10.下列程序中,函数FUN的功能是:计算并输出K以内最大的10个能被 13 或17整除的自然数之和.
 int fun(int k)
 {int m=0,mc=0;
 while ((k>=13)||(mc<10))                  /*$ERROR1$*/ while((k>=13)&&(mc<10))
{if((k%13= =0)&&(k%17= =0))                 /*$ERROR2$*/ if((k%13= =0)||(k%17= =0))
{m+=k; mc++;}
k++;                                       /*$ERROR3$*/ k--;
return(m);
}
main()
 {printf("%d\n",fun(500));
}
11.以下程序将输入的数字字符序列转化成一个整数.
#include<stdio.h>
#include<string.h>
main()
{char c[10];  int i=0,j;  long k=0;
gets(c);  j=strlen(c);
for(;i<j;i++)
if(c[i]>='0'||c[i]<='9')          /*$ERROR1$*/ if(c[i]>='0'&&c[i]<='9')
k=k*10+c[i];                  /*$ERROR2$*/k=k*10+c[i]-'0';
printf("k=%d\n",k);             /*$ERROR3$*/ printf("k=%ld\n",k);
}
12.以下程序计算200以内的其平方具有回文性质的正整数的数目如:11^2=121,111^2=12321
#include<stdio.h>
sqrtes(int x)
{ int s,y;
 s=x*x;   y=0;
while(s)
 {y=y*10+s/10;                       /*$ERROR1$*/ y=y*10+s%10;
s=s%10; }                              /*$ERROR2$*/ s=s/10;
if(y=x*x) return 1;                /*$ERROR3$*/ if(y= =x*x) return 1;
else return 0;
}
main()
{ int n,count=0;
for(n=10;n<200;n++)
if(sqrtes(n)) {count++; printf("n=%3d,n*n==%d\n",n,n*n);}
printf("count=%d\n",count);
}
13.以下程序将十进制正整数n转换成十六进制数,并存入字符串str中.
Main()
{unsigned n,h;  int i=0;
printf("input a decimal Number to n:");  scanf("%d",&n);
do
 {h=n/16;                               /*$ERROR1$*/ {h=n%16;
 str[i++]=(h<=9)?h+'0':h+'A'-10;
n=n%16;                                 /*$ERROR2$*/ n=n/16;
} while(n);
for(--i;i>=0;)
 printf("%s",str[i--]);                  /*$ERROR3$*/ printf("%c",str[i--]);
printf("\n");
}
14.以下程序能够将字符串str1和字符串str2 合并成一个新字符串str3.
 #include<stdio.h>
main()
{char str1[30],str2[20],str[60];    int i=0,j=0;
printf("Enter first string:");  gets(str1);
printf("Enter second string:");  gets(str2);
while(str1[i]) str[i]=str1[i];i++;     /*$ERROR1$*/ while(str1[i]){str[i]=str1[i],i++}
while(str2[j])str[i++]=str2[j];j++;   /*$ERROR2$*/ while(str2[j]){str[i++]=str2[j];j++;}
str[i]="0";                          /*$ERROR3$*/ str[i]='0';
printf("str=%s\n",str);
}
15.以下程序实现字符串反向存储.
Main()
{char str[70],ch,*p,*temp;
 printf("Enter string to str:");  scanf("%s",str);  
p=str;  temp=str;
while(temp) temp++;                      /*$ERROR1$*/ while(*temp) temp++;
 *temp--;                                /*$ERROR2*/ temp--;
while(p>temp)                                /*$ERROR3$*/  while(p<temp)
 {ch=*p;*p++=*temp;*temp--=ch;}
printf("string=%s\n",str);
}

二、填空题
1.计算学生的平均成绩和不及格的人数.
Struct stu
{ int num;
 char *name;
 char sex;
 float score;
};
main()
{ ______ student[5]={ {101,"Li ping",'M',45},         /*$BLANK1$*//* struct stu*/
                   {102,"Zhang ping",'M',62.5},
                   {103,"He feng",'F',92.5},
                   {104,"Cheng ling",'F',87},
                   {105,"Wang ming",'M',58},
                  };
int i,c=0;   float ave,s=0;
for(i=0;i<5;i++)
{ s+=_____;                                       /*$BLANK2$*//*student[i].score;*/
 if(____<60) c++;                                 /*$BLANK3$*//* student[i].score*/
 }
ave=s/5;
printf("average=%f\n count=%d\n",ave,c);
}
2.完善程序,使5×5数组的对角线元素为1,其它为0,即输出5×5的对角矩阵.
#include<stdio.h>
main()
 {int j,k,a[5][5];
 for(j=0;j<5;j++)
  for(k=0;k<5;k++)
{if(___)                   /*$BLANK1$*//* k= =j*/
  _____                    /*$BLANK2$*//* a[j][k]=1*/
else_____ ;                /*$BLANK3$*//* a[j][k]=0*/
}
for(j=0;j<s;j++)
{for(k=0;k<5;k++)  printf("%d",a[j][k]);
printf("\n");
}}
3.编制函数acopy(), 将数组a的内容复制到b数组中(以-999作结束标志),程序未完成,请填空.
#include<stdio.h>
void acopy(____)              /*$BLANK1$*//* void acopy(int a[],int b[])*/
{int i=0;
  while(a[i]!=-999)
  {____ ;                  /*$BLANK2$*//* b[i]=a[i]*/
i++;}
b[i]=a[10];}
main()
{static int a[]={1,3,5,7,9,2,4,6,8,10,-999}; int b[80],i=0;
____ ;                                       /*$BLANK3$*//*acopy(a,b) */
while(b[i]!=-999)  printf("%d",b[i++]);}
4.以下程序用函数的递归调用打印n的阶乘值,请填空.
 Long fac(int n)
{ long f;
if(n<0) printf("n<0,data error");
else if(n= =0||n= =1) f=1;
else f=____                          /*$BLANK1$*//* else f=n*fac(n-1);*/
  ______ ; }                           /*$BLANK2$*//* return(f);*/
main()
     {int n;   long y;
printf("input a integer number:");
scanf("%d",&n);
y=____ ;                          /*$BLANK3$*//* y=fac(n);*/
printf("%d!=%ld",n,y);
}
 5.有一个3×4的矩阵,要求编程以求出其中最大的那个元素,以及它所在的行号和列号.程序如下:
 main()
{int i,j,row,col,max;
  static int a[3][4]={{3,5,1,8},{6,4,11,7},{9,3,10,2}};
max=___ ;                                  /*$BLANK1$*//*a[0][0] */
for(i=0;i<3;i++)
  for(j=0;j<4;j++)
if(___________)                           /*$BLANK2$*/     /*a[i][j]>max*/
 {max=_______;                          /*$BLANK3$*/      /*max=a[i][j]*/
  row=i; col=j;
}
6.删除一个字符串中的某个特定字符(设本例中要删除的特定字符为s)。
main()
{char a[]="this is a book";   char c='s';
int i,j=0;
for(i=0;a[i]!=_____;i++)                    /*$BLANK1$*/    /*'\0'*/
if(a[i]!=______)                           /*$BLANK2$*/    /*c*/
  a[j++]=a[i];
______='\0';                              /*$BLANK3$*/    /*a[j]*/
printf("%s",a);
}
7.用冒泡法对10个数排序(从小到大),,程序如下:
main()
{int a[11];  int i,j,t;
printf("Enter 10 numbers:\n");
for(i=1;i<11;i++)
  scanf("%d",_____);                      /*$BLANK1$*/  /*&a[i]*/
printf('\n");
for(j=1;j<=9;j++)
  for(i=1;i<=____;i++)                     /*$BLANK2$*/   /*10-j*/
    if(___________)                       /*$BLANK3$*/   /*a[i]>a [i+1]*/
     {t=a[i];a[i]=a[i+1];a[i+1]=t;}
printf("The sorted numbers:\n");
for(i=1;i<11;i++)
  printf("%d",a[i]);
}
8.以下程序中,主函数调用了LineMax函数,实现N行M列的二维数组中,找出每一行上的最大值。
#define  N  3
#define  M  4
void linemax(int a[N][M])
{int i,j,p;
 for (i=0;i<N;i++)
   {p=0;
    for (j=1;j<M;j++)
       if(a[i][p]<a[i][j])
       _____________;                        /*$BLANK1$*/   /*p=j*/
printf("The max value in line %d is %d\n",i,_____);   /*$BLANK2$*/    /*a[i][p]*/
9.编程输出以下的杨辉三角(输出前10行)
1
1   1
1   2   1
1   3   3   1
1   4   6   4   1
1   5  10  10   5   1
1   6  15  20  15   6   1
……
#define  N  10
main()
{int i,j,a[N][M];
for(i=0;i<N;i++)  {a[i][i]=1;  _____=1;}       /*$BLANK1$*/  /*a[i][0]*/
for(i=2;i<N;i++)
  for(j=1;j<=i-1;j++)
   a[i][j]=______________;                 /*$BLANK2$*/  /*a[i-1][j-1]+a[i-1][j]*/
for(i=0;i<N;i++)
{for(j=0;______;j++)                      /*$BLANK3$*/    /* j<=i*/
   printf("%5d",a[i][j]);
printf("\n");}
}
10.写两个函数,分别求两个整数的最大公约数和最小公倍数,用主函数调用这两个函数并输出结果。
main()
{int m,n,cd,cm,
 printf("Input two numbers,please:\n"); scanf("%d%d",&m,&n);
cd=gcd(m,n);
cm=gcm(__________);                      /*$BLANK1$*/    /*m,n,cd*/
printf("gcd=%d\n",cd);   printf("gcm=%d\n",cm);}

int gcd(int a,int b)
{int t;
 if(a<b){t=a;a=b;b=t;}
while(_______)                            /*$BLANK2$*/    /*b!=0*/
{t=______;a=b;b=t;}                        /*$BLANK3$*/    /*a%b*/
return(a);}

intgcm(inta,int b,int h)
{return a*b/h;}
11.求数组的平均值。
#include<stdio.h>
float mean (_______________)               /*$BLANK1$*/      /*int *x,int num*/
{int i;  float avg;
 for(_______,i=0;i<num;i++)                 /*$BLANK2$*/       /*avg=0*/
   avg+=x[i];
avg/=num;
___________;                             /*$BLANK3$*/      /*return(avg)*/
}

main()
{int i,a[15];
 for(i=0;i<15;i++)
   a[i]=i+1;
   printf("average:%6.2f\n",mean(a,15));
}

12.以下程序输出如下图所示的九九表。
1   2    3   4   5   6   7   8   9
1
2 4
3 6   9
4 8   12  16
5 10  15  20  25
6 12  18  24  30  36
7 14  21  28  35  42  49
8 16  24  32  40  48  56  64
9 18  27  36  45  54  63  72  81
#include<stdio.h>
main()
{int i,j;
 for(i=1;_______;i++)                      /*$BLANK1$*/     /*i<10*/
 printf("%4d",i);  printf("\n--------------------------------\n");
 for(i=1;i<10;i++)
    for(j=1;________;j++)                  /*$BLANK2$*/     /*j<=i*/
printf((j= =i)? _________:"%4d",i*j);  }        /*$BLANK3$*/     /*"%4d\n"*/
13.已知一个首项大于0的等差数列前四项只和是26,积是880,求该四项之值。
#include<stdio,h>
main()
{int sum,product,dif,a1,a2,a3,a4;
for(a1=1;a1<5;a1++)
  for(dif=1;dif<5;dif++)
    {a2=a1+dif;  a3=a1+2*dif;  a4=a1+3*dif;
    _____=a1+a2+a3+a4;                   /*$BLANK1$*/   /*sum*/
    _____=a1*a2*a3*a4;                   /*$BLANK2$*/   /*product*/
   if(sum= =26___product= =880)            /*$BLANK3$*/   /*&&*/
   printf("a1=%2d, a2=%2d, a3=%2d, a4=%2d\n",a1,a2,a3,a4);
}
14.以下程序输入一行字符,统计其中每种数字字符的个数,存放到一维数组a中,并输出a中不为0的元素值。
#include <stdio.h>
main()
{char ch;   int i,a[10]={0};
while((ch=getchar())!=_____)                /*$BLANK1$*/  /*'\n'*/
    if(ch>='0'____ch<='9')                /*$BLANK2$*/   /*&&*/
     a[ch-'0']++;
for(i=0;i<=9;i++)
 if(_____!=0)                              /*$BLANK3$*/  /*a[i]*/
   printf("a[%d]=%d\n",i,a[i]);
}
15.以下程序编写了一个求n×n数组a的两条对角线上元素之和的函数。
#define  N  5
#include<stdio.h>
int sumfun(int a[N][N])
{int i,j,sum_____;                         /*$BLANK1$*/    /*=0*/
for(i=0;i<N;i++)
  for(j=0;j<N;j++)
     if(i=j____i+j= =N-1)                  /*$BLANK2$*/   /*||*/
sum+=a[i][i];
return sum;
}
main()
{int i,j,k=0,a[N][N];
 for(i=0;i<N;i++)
   {for(j=0;j<N;j++)
       {a[i][j]=++k;
        printf("%5d",a[i][j]);}
    printf('\n");}
printf("the sum =%8d\n",sumfun___;          /*$BLANK3$*/   /*(a)*/
}
16.打印出1-100间能被3整除且尾数是6的数
main()
{            ;                          /*$BLANK1$*/   /*int i,j;*/
 for(i=0;    ;i++)                        /*$BLANK2$*/   /*i<10*/
  {j=i*10+6;
   if(       =0)  continue;               /*$BLANK3$*/   /*j%3!*/
   printf("%d",j);}
}

三、编程题
1.求解满足条件1+2+3+……+n 1000的最小n的值。输出格式:n=235
main()
{Int s,n=1;
s=0;
while((s+=n++)<1000);n--;
printf("n=%d\n",n);
}
2.利用循环语句求1-1/3+1/5-1/7+……+1/(2n-1)的值(直到第100项的和)输出格式(6位小数):s=0.235167
main()
{float s=0;
int n=1,f=1;
while(n<=100)
{s+=f*1.0/(2*n-1);
n++;f=-f;
printf("s=%﹒6f\n",s);
}
3.求ex=1+x+x^2/2!+x^3/3!+……+x^n/n!(- <+ ),要求:(1)用x=2,n=8编程(2)保留3位小数(3)不许使用系统数学函数   输出格式:ex=3.518
main()
{float ex=1,x=2,t=1,x1;
int n; x1=x;
for (n=1;n<9;n++)
{t=t*n; ex=ex+x1/t; x1*=x;}
printf("ex=%﹒3f\n",ex);}
 
4.计算1~500之间的全部"同构数"之和。所谓"同构数"是指一个数,它出现在它的平方的右端。如6的平方是36,6出现在36的右端,6就是"同构数"。输出格式:36。
main()
{int s=0,i,n,m=1;
 for(i=1;i<501;i++)
{m=1;n=i;
while(n) {m=m*10;n=n/10;}
m=i*i%m;
if(m= =i) {s+=i;
printf("i=%d,i*i=%d\n",i,i*i);}
}
printf("%d\n",s);}
5.利用下面的公式求s的值s=1*2*3-2*3*4+3*4*5-4*5*6+5*6*7……-18*19*20+19*20*21-20*21*22  输出格式:s=2.3516
main()
{int f=1,i;
float s=0;
for(i=1;i<21;i++)
{s+=f*i*(i+1)*(i+2); f=-f;}
printf("s=%d",s);
}
6.统计有1,2,3,4四个数组成的4位数的个数。要求:1)允许4位数中有相同的数字2)个位数和百位数不同。例如:符合的有:1122,1244,2134,22333不符的有:1424,2313(个位数和百位数相同)输出格式;n=235
main()
{int i,j,k,m,n=0;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
  for(k=1;k<5;k++)
for(m=1;m<5;m++)if(m!=j)n++;
printf("n=%d",n);}
7.打印出所有的"水仙花数"之和,所谓"水仙花数"是指一个三位数,其各位数字的立方和等于该数本身。例如153是一个"水仙花数",因为153=1^3+5^3+3^3输出格式:23456
main()
{int s=0,k,a,b,c;
for(k=100;k<1000;k++)
{a=k/100;b=k%10;c=(k%100-b)/10;
if(k= =a*a*a+b*b*b+c*c*c) s+=k;}
printf("%d\n",s);
}
8.求s=1+1+2+3+5+8+13+21+34……的和。其中:1)从第三项开始每一项的值等于前两项的和,例如:2=1+1,3=1+2,5=2+3……。2)计算30项的和(包括两个1) 输出格式:s=23516234
main()
{int k;
long f1=1,f2=1,f3,s;
s=f1+f2;
for(k=3;k<31;k++) {f3=f1+f2;s+=f3;f1=f2;f2=f3;}
printf("s=%ld\n",s);
}
9.设有字符串char src[ ]= "S>h?e*-$i#$s@Aglir?l,s/hei%s(f)r[]m{E}n23g%&land";统计字符ASCII码值连续的次数。[说明]字符连续是说在ASCII表上连续。输出格式:n=30
#include<math.h>
main()
{char
src[ ]="S>h?e*-$i#$s@Aglir?l,s/hei%s(f)r[]m{E}n23g%&land";
int k=0,n=0;
while(src[k+1])
{if(abs(src[k]-src[k+1])= =1)n++;k++;}
printf("n=%d\n",n);
}
10.设有10个学生的成绩分别为89,90,84,78,84,67,88,92,79,73,存放在数组stu中,输出他们的平均成绩aver(保留两位小数)和低于平均成绩的人数。输出格式aver=80.34,n=7
main()
{int stu[10]={ 89,90,84,78,84,67,88,92,79,73}
float aver=0;
int k,n=0;
for(k=0;k<10;k++)
aver+=stu[k];aver/=10;
for(k=0;k<10;k++)
if(stu[k]<aver)n++;
printf("aver=%﹒2f,n=%d",aver,n);
}

11.输出100~200之间的全部素数的和。输出格式:s=23516
main()
{int k,j,s=0,f;
for(j=101;j<201;j++)
{f=1;
for(k=2;k<j/2;k++)
{if(j%k) continue;else {f=0;break;}}
if(f) s+=j;}
printf("s=%d\n",s);}
12.编写程序,对一个正整数,将各位数字反序后的数输出。例如:原数是12345,则计算机输出的数是:54321。要求:必须用循环机构实现编程。输出格式:s=23516
main()
{int n=7613,s=0;
while(n){s=s*10+n%10;n/=10;}
printf("s=%d",s);
}
13.编写程序,计算并输出6666666的约数中最大的四位数
main()
{int n=9999;
while(n>999) if(6666666%n)n--;
else break;
printf("n=%d\n",n);}
14.编写程序,计算1+1/x+1/x^2+1/x^3+1/x^4……,直到1/x^n<0.000001为止。说明:上式中x=3,x^n表示x的n次方。
main()
{float s=1.0;
int x=3,t=x;
while(1.0/t>=0.000001) {s+=1.0/t; t*=x;}
printf("s=%f\n",s);
}
15.计算任一个自然数n(本题n=6)的立方均可由n个连续的奇数之和来表示,将这n个连续的奇数中最小的数输出。
main()
{int n=6,min,i;
long m=n*n*n,sum=0;
for(i=1;i<n;i++)sum+=2*i;
min=1;
while(n*min+sum!=m) min+=2;
printf("min=%d\n",min);
}
16.求s=1!+2!+3!+4!+……+10!
main()
{int n;
long s=0,i=1;
for(n=1;n<11;n++) {i*=n; s+=i;}
printf("s=%ld\n",s);
}
17选择法排序(书p223)
18将字符串a复制为字符串b(书p234)

 

阅读(5073) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册