例如:当str1=“cdefghij”,然后输入4,则str2=“cdef”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define LEN 80
main()
{
char str1[LEN),str2[LEN);
int n,i;
clrscr();
printf(“Enter the string:\n”);
gets(str1);
printf“Enter the position of the string
deleted:”);
scanf(【 】);
for(i=0;i<n;i++)
【 】
str2[i]=‘\0’;
printf(“The new string is:%s\n”,【 】);
}
第1题
已知字符A的ASCII代码值为65,以下程序运行时若从键盘输入:B33<回车>,则输出结果是【 】。
include
main()
{ char a, b;
a=getchar(); scanf("% d", &b);
a=a-'A'+'0'; b=b*2;
printf("% c % c\n", a, b);
}
第2题
在t中。例如,当s中的数为7654321时,t中的数为642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
include <conio.h>
/*************found**************/
void fun(long s,long t)
{ long s1=10;
s/=10;
*t=s%10;
/*************found**************/
while(s<0)
{ s=s/100;
*t=s%10*s1+*t;
s1=s1*10;
}
}
main()
{ long s, t;
clrscr();
printf("\nPlease enter s: "); scanf
("%ld",&s);
fun(s,&t);
printf("The result is: %ld\n ",t);
}
第3题
到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:1,1,1,2,2,2,3, 4,4,5,5,6,6,7,7,8,9,9,10,10。
删除后,数组中的内容应该是:1,2,3,4,5,6,7, 8,9,10。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
define N 80
int fun(int a[],int n)
{
int i, t,j=0;
t=a[0];
for(i=1;i<n;i++)
if(【 】)
;
else
{
【 】;
t=a[i];
}
a[j++]=t;
return j;
}
main()
{
int a[N]={1,1,2,2,2,3,4,4,5,5,6,6,6,
7,7,8,9,9,10,10},i,n=20;
printf("The original data:\n");
for(i=0; i<n; i++)
printf("%4d",a[i]);
n=fun(a,n);
printf("\n\nThe data after deleted ;
\n");
for (i=0;i<n;i++)
printf("%4d",a[i]);
printf("\n");
}
第4题
放在1中。高位仍在高位,低位仍在低位。
例如,当s中的数为:7654321时,t中的数为:7531。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
第5题
60,69),{90,96,84.5,100,85},{92,97,86,73,85))时,五门学科的平均分为:89 85 86.7 77.7 79.7。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填人所编写的若干表达式或语句。 试题程序: include<stdlib.h> include<stdio.h> define N 3 define M 5 int main { int i,j; static float score[N][M]一{{85,62,89.5,60,69), {90,96,84.5,100,85},{92,97,86,73,85}}; static float arr[-N]; system("CLS"); for(i=0;i<M;i++) arr[i]=0.0: for(i=0;i<【1】 ;i++) { for(j=0;j<【2】 ;j++) arr[j]+=score[i][j]: } for(i=0;i<M;i++) printf("\nsubject%d\taverage=%5.1f",i+1, 【3】); return 0; }
第6题
roc 的功能是:计算并输出该数列前n项的和sum。n的值通过形参传人。例如,当n=20时,程序的输出结果应为42762.000000。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动maiil函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdlib.h> include<conio.h> include<stdio.h> double proc(int n) { double sum,s0,s1,s2,s; int k; sum=1.0; if(n<=2) sum=0.0; s0=0.0; s1=0.0; s2=1.0; //****found**** for(k=4;k<n;k++) } { s=s0+s1+s2; sum+=S: s0=s1; s1=s2; //****found**** s2=s; return sum; } void main { int n; system("CLS"); printf("Input N="); scanf("%d",&n J; printf("%f\n",proc(n)); }
第7题
组成一个新的字符串。 例如,若字符串数组中的M个字符串为: ABCD BCDEFG CDEFGHI 则合并后的字符串内容应该是ABCDBCDEFGCDEF—GHl。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的花括号中填人所编写的若干语句。 试题程序: include<stdio.h> include<conio.h> define M 3 define N 20 void proc(char arr[M][N],char*b) {
} void main { char str[M][N]={"ABCD","BCDEFG"," CDEFGHI"},i; char arr[100]={" "); printf("The string:\n"); for(i=0;i<M;i++) puts(str[i]); printf("\n"); proc(str,arr); printf("The A string:\n"); printf("%s",arr); printf("\n\n"); }
第8题
编写函数fun(),它的功能是:计算和输出下列级数的和。
S=1/(1×2)+1/(2×3)+…+1/(n×(n+1))
例如,当n=10时,函数值为0.909091。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序;
include<conio.h>
include<stdio.h>
double fun(int n)
{
}
main ( )
{
clrscr();
printf("%f\n",fun(10));
}
第9题
请补充main函数,该函数的功能是:从键盘输入3个整数,然后找出最大的数并输出。
例如,输入:12,45,43,最大值为45。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
main()
{
int a, b, c, max;
clrscr();
printf("\nlnput three numbers:\n");
scanf("%d,%d,%d",&a,&b,&c);
printf("The three numbers are:%d,
%d,%d\n",a,b,c);
if(a>b)
【 】;
else
【 】;
if(max<c)
【 】;
printf("max=%d\n",max);
}
第10题
。高位仍在高位,低位仍在低位。例如,当s中的数为87653142时,t中的数为8642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main,~数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
void fun(long s,long *t)
/**********************************/
{ int d;
long s1=l;
*t=0;
while(s>0)
{ d=s%10;
/**********************************/
if(d%2=0)
{*t=d*sl+*t;
sl*=10
}
/**********************************/
s\=10;
}
}
main ( )
{ long s,t;
clrscr();
printf("\nPlease enter s: "); scanf
("%ld",&s);
fun(s,&t);
printf("The result is :%ld\n",t);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!