1、二、改错题
Cmody191.c
修改程序,用以计算1~100之间所有偶数之和。
#include
2、不含对角线)各元素加4,右上半三角(含对角线)各元素乘2。
#include 3、 for(i=0;i 4、mody201.c
修改程序,计算满足如下条件整数n最大值。
22+42+62+82+……+n2<1000
#include 5、字符。
例如:输入字符串为”welcome”,m=2,n=3,则截取字串为”elc”
#include 6、n with %d and %d!\n",m,n);
else
{ i=0;
/**/ while(i<=n) /**/
{
/**/ sub[i]=str[m+i];/**/
i++;
}
/**/ sub[i]='\n';/**/
printf("sub string is:%s\n",sub);
}
getch();
}
Cmody211.c
修改程序,实现输入一整型二维数组,计算其中数组元素最大值与最小值差。
#include 7、define ROW 3
#define COL 4
void main()
{
int a[ROW][COL],max,min,i,j,result;
clrscr();
printf("Enter array a:\n");
for(i=0;i 8、/)
min=a[i][j];
if(a[i][j]>max)
/**/ max=a[i][j] /**/
}
printf("Result= %d\n",max-min);
getch();
}
Cmody212.c
修改程序cmody212.c,实现从键盘输入一串字符和一种字串,输出该子串在原字符串中浮现次数。
#include 9、100],s2[100];
printf("Enter main String:");
gets(s1);
printf("Enter Sub String:");
gets(s2);
count=0;
/**/ for(i=0;*s1!='\0';i++) /**/
{
/**/ for(k=0;(s1[j]==s2[k])&&(s1[j]!='\0');j++,k++ );/**/
if(s2[k]=='\0') count++;
}
printf("\nCount=%d\n",count);
getch();
10、
}
Cmody221.c
修改程序,输出存储在构造体数组中8位学生成绩平均分以及最高学生姓名
#include 11、mrk;
float total=0,aver,max;
max=stu[0].score;
mrk=0;
while(i<8)
{
/**/ total=total+stu[i]; /**/
if(stu[i].score>max)
{max=stu[i].score;
mrk=i;
}
/**/ i++ /**/
}
aver=total/8;
printf("\naver=%.2f \n Best is %s\n",aver,stu[mrk].n 12、ame);
getch();
}
Cmody222.c
修改程序,完毕其中n个字符串升序排列
#include 13、trcpy(temp,s[i]);
strcpy(s[i],s[j]);
strcpy(s[j],temp);
}
}
void main()
{
int i;
char str[][COL]={"DEF","BAEELCS","FHIAME","CBADF","APMAE"};
/**/ fun(str,COL);/**/
clrscr();
for(i=0;i 14、c,实现将输入十进制正整数转换成十六进制数,且用字符串存储该十六进制数
#include 15、/ s[i]=b /**/;
x=x/16;
i++;
}
printf("\nHex number is:");
for(j=i-1;j>=0;j--)
putchar(/**/ s[i] /**/);
getch();
}
Cmody232.c
修改程序cmody232.c,输出下列9行数字金字塔
1
121
12321
1234321
………………………
54321
#include 16、 int i,j,k;
for(k=1;k<=9;k++)
{
/**/ for(i=0;i<=k;i++) /**/
printf(" ");
for(i=1;i<=k;i++)
printf("%d",i);
/**/ for(j=k-1;j>1;j--) /**/
printf("%d",j);
printf("\n");
}
getch( );
}
三、填空题
Ccon191.c
程序ccon 17、191.c,从键盘输入3个实型值,若它们能构成一种三角形(即任意两边之和不不大于第三边),则依照如下公式求该三角形面积;否则,提示相应信息。
#include 18、 /**/;
printf("area is %.2f\n",area);
}
else
printf("Not Triangle!\n");
getch();
}
Ccon192.c
程序ccon192.c,计算:已知大货车限载8吨、中型货车限载3吨、微型货车限载1吨,需50辆车运送100吨货品时,应配备大、中、微型车分别多少辆?共有多少种解决方案?
#include 19、
int big,median,small,n=0;
printf(" big median small \n");
for(big=0;big<=13;/**/ /**/)
for(median=0;median<=33;median++)
{
small=100-8*big-3*median;
if(/**/ /**/==50)
{
n++;
printf("%d-->%2d %2d %2d\n 20、",
n,big,median,small);
}
}
return n;
}
void main()
{
int num;
num = fun();
printf("\n There are %d solutions.\n",num);
getch();
}
Ccon201.c
程序ccon201.c,按照如下袋装状况求一堆苹果总数,总数在100~300之间。若按每袋装8个苹果则多余5个,若按每袋装7个苹果,则多余4个,若按每袋装5个苹果,则多余2个。
#include 21、{
int n;
for( n=300;/**/ /**/;n-- )
{if( n%8 == 5)
if( !((n-4)%7) /**/ /**/)
printf("n=%d\n",n);
}
getch();
}
Ccon202.c
程序ccon202.c中swap函数,通过指针变量实现两个变量值互换。
#include 22、
*p1 =/**/ /**/;
*p2 = sum-*p1;
}
void main()
{
int x,y;
printf("please input 2 numbers:\n");
scanf("%d,%d",&x,&y);
printf("\nOriginal:x=%d y=%d\n",x,y);
swap(&x,&y);
printf("\nNow:x=%d y=%d\n",x,y);
getch();
}
Ccon211.c
程序ccon211.c,按每行最多5个数方式输出100~400之 23、间能同步被7和4整除所有数及它们之和。
#include 24、rintf("\n sum=%d\n",sum);
getch();
}
Ccon212.c
程序ccon212.c中cmob函数用以输出等式a*b*c+a*c*c=560所有a,b,c组合(其中a,b,c只取1~9之间一位整数)。如a=7,b=2,c=8时,7*2*8+7*8*8=560
#include 25、{
if(/**/ /**/ ==m)
printf("a=%d,b=%d,c=%d\n",a,b,c);
}
}
void main()
{
int result=560;
comb(result);
getch();
}
Ccon221.c
程序ccon221.c,输出如下图形
% % % % % % %
& & & & & &
% % % % %
& & & &
% % %
& &
%
#include 26、 27、Ccon222.c
程序ccon222.c中pnt函数,依照参数n(2≤n≤10),输出类似如下所示方针(n=5).
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25
#include 28、0)
a[i][j]=/**/ /**/;
else
a[i][j]=i*n+n-j;
}
printf("array a(n=%d) is:\n",n);
for(i=0;i 29、
scanf("%d",&n);
pnt(/**/ /**/,n);
getch();
}
Ccon231.c
程序ccon231.c,计算如下分数序列前18项之和
#include 30、
printf("sum=%f\n",sum);
getch();
}
Ccon232.c
程序ccon232.c中inv函数,通过指针变量将字符串str内容”asdfjk”,调用inv函数后,变成:”kjfdsa”。
#include 31、 *(str+j)=/**/ /**/;
}
}
void main( )
{
char str[]="asdfjk";
printf("\n Original is:%s\n",str);
inv(str);
printf("\n Now is:%s\n",str);
getch();
}
四、编程题
cprog191.c
打开程序cprog191.c,完毕其中fun函数:依照输入汇款数额,求应交汇费。设应交汇费计算公式如下:
#include 32、
double fun(float x)
{
/**/
/**/
}
void main()
{
float x;
double y;
clrscr();
printf("Please input a number:\n");
scanf("%f",&x);
y = fun(x);
printf("f(%.2f)=%.2f\n",x,y);
getch();
}
cprog192.c
打开程序cprog192.c,完毕其中fun函数:对4×4矩阵从顶行开始各行按从左到右顺序查找,找出各行中0元素之后所 33、有负数,并按元素浮现先后顺序存储到数组b中,并返回这些负数之和。如矩阵为:
则调用函数fun( )后,数组b各元素依次为-3,-1,-4,-3,-12,-13,并返回-36.
#include 34、0,-4},
{0,3,-3,-12},{21,0,-13,3}};
int arrb[LEN],i,result;
for(i=0;i 35、 );
}
cprog201.c
打开cprog201.c,完毕其中函数fun,该函数数学表达式是
#include 36、tch();
}
cprog202.c
打开程序cprog202.c,完毕其中fun函数:
函数fun(double x,int n),用如下公式近似计算cos(x)值:
#include 37、
}
double fun(double x,int n)
{
/**/
/**/
}
cprog211.c
打开cprog211.c,完毕其中函数fun,该函数数学表达式是
#include 38、
scanf("%f",&x);
y = fun(x);
printf("f(%.2f)=%.2f\n",x,y);
getch( );
}
cprog212.c
打开程序cprog212.c,完毕其中fun函数:对两个字符串中小写英文字母个数进行比较,并返回比较成果。(注:第1个字符串比第2个字符串小写英文字母个数多,则返回正数,相等返回0,个数少则返回负数)
例如:字符串str1为“abc123”,字符串str2为”abcd”,则函数fun返回值应不大于0。
#include 39、2)
{
/**/
/**/
}
void main( )
{
int rela;
char *str1,*str2;
clrscr();
printf("Please input string NO.1:");
gets(str1);
printf("Please input string NO.2:");
gets(str2);
rela=fun(str1,str2);
if(rela>0)
printf("Numbers of Lower char in %s > Numbe 40、rs of Lower char in %s",str1,str2);
if(rela==0)
printf("Numbers of Lower char in %s = Numbers of Lower char in %s",str1,str2);
if(rela<0)
printf("Numbers of Lower char in %s < Numbers of Lower char in %s",str1,str2);
getch();
}
cprog221.c
打开程序cporg221.c,完毕其中fun函数:依照输入x和y值,按 41、如下公式计算:
将计算成果整数某些存入数组元素arr[0],并将该计算成果小数某些前两位存入arr[1]中。
#include 42、 if((x>1.0 &&x<2.0)&&(y>0 && y<=6))
{
fun(arra,x,y);
printf("\npart1=%d,part2=%d",arra[0],arra[1]);
}
else
printf("x or y is out of range!");
getch();
}
cprog222.c
打开程序cprog222.c,完毕其中fun函数:将一种升序数组a和一种降序数组b中所有元素按降序存入数组c中。
例如:数组a为{5,10,15,27,46},数组b为{50,45,42,2 43、9,15,8,5,2},则数组c就应为{50,46,45,42,29,27,15,15,10,8,5,5,2}。
#include 44、 printf("array arra is:");
for(k=0;k 45、og231.c,完毕其中函数fun,该函数递归公式是:
#include 46、
/**/
}
cprog232.c
打开程序cprog232.c,完毕其中fun函数:返回一维数组中次大数(即仅不大于最大数数),设数组a中没有重复元素。
例如:数组元素为{45,58,33,24,40,20,30,28,31},函数fun返回值为45.
#include 47、x_pre,i;
max_pre=fun(arra);
printf("array arra is:");
for(i=0;i 48、/;→if(i!=(i/2)*2)
cmody192.c
/**/ for(j=0;j<=i;j++)/**/→for(j=0;j 49、str[m-1+i];
/**/ sub[i]='\n';/**/→sub[i]= '\0'
cmody211.c
/**/ max=min=0;/**/→max=min=a[0][0];
/**/ mina[i][j]
/**/ max=a[i][j] /**/→max=a[i][j];
cmody212.c
/**/ for(i=0;*s1!='\0';i++) /**/
→for(i=0;*(s1+i)!=’\0’;i++)
/**/ for(k=0;(s1[j]==s2[k])&&(s1[j]!='\0');j++, 50、k++ );/**/→
for(k=0,j=i;(s1[j]==s2[k]&&(s2[k]!=’\0’);j++,k++);
cmody221.c
/**/ structure student /**/→struct student
/**/ total=total+stu[i]; /**/→
total=total+stu[i].score
/**/ i++ /**/→i++;
cmody222.c
/**/ for (j=i+1;j






