更多"改错题
下列给定程序中函数fun( )的功能是计算正整数num的各位"的相关试题:
[简答题]改错题
下列给定程序中函数fun( )的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
long fun(long num)
{
/**********************found***********************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/**********************found***********************/
}while(num)
return (k);
}
main( )
{
long n;
clrscr( );
printf("/Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
}
[填空题]下列给定程序中函数fun( )的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
long fun(long num)
/*+**+*+*+*found************/
long k=1;
do
k+=(num%10)*(num%10);
num/=10;
/*********+found*+**+*+******/
while(num)
return(k);
main( )
long n;
clrscr( );
printf("/Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
[简答题]下列给定程序中,函数fun的功能是:计算正整数num各位上的数字之积。
注意:不要改动maln函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h >
#include <conio.h>
long fun (long num)
/********** found********** /
long k;
do
k*=num% 10;
/********** found********** /
num/=10;
while (num);
return (k);
main ( )
long n;
printf ("/ n please enter a num-
ber: ");
scanf("% 1d", &n);
printf("/n% 1d/n", fun(n));
[简答题]下列给定程序中函数fun的功能是:计算正整数num各位上的数字之积。
例如,若输入252,则输出应该是20。若输入202,则输出应该是0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <conio.h>
long fun(long mum)
/********** found********** /
long k;
do
k*=num% 10;
/********** found********** /
num/=10;
while(mum);
return(k);
main( )
long n;
printf("/n please enter a number: ");
scanf("%ld", &n);
printf("/n% ld/n", fun(n));
[填空题]下列给定程序中,函数proc( )的功能是计算正整数m各位上数字的平方和。
例如,输入498,则输出应该是161。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main( )函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
long proc(long m)
{
//****found****
long sum=1;
do
{
sum+=(m%10)*(m%10);
m/=10;
//****found****
}
while(m)
return(sum);
}
void main( )
{
long n;
system("CLS");
printf("Please enter a number:");
scanf("%1d",&n);
printf("/n%1d/n",proc(n));
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
/**********************found***********************/
int fun(char t[ ])
{
char c;
int i,j;
for(i=0;i
[简答题]改错题
下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之和。high由主函数传给fun( )函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
int fun(int high)
{
int sum=0,n=0, j, yes;
while(high>=2)
{
yes = 1;
for(j=2; j<=high/2; j++)
/**********************found***********************/
ifhigh%j==0
{
yes=0;
break;
}
/**********************found***********************/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}
return sum;
}
main( )
{
clrscr( );
printf("%d/n",fun(100));
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是找出100~n(不大于1000)之间百位数字加十位数字等于个位数字的所有整数,把这些整数放在s所指的数组中,个数作为函数值返回。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#define N 100
int fun(int *s, int n)
{
int i,j,k,a,b,c;
j=0;
for(i=100; i 1000);
num= fun(a,n);
printf("/n/nThe result :/n");
for(i=0; i
[简答题]改错题
下列给定程序中,函数fun( )的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
void fun(char *p,char *q,char *c)
{ int k=0;
while(*p||*q)
/**********************found***********************/
{ if (*p<=*q)
c[k]=*q;
else c[k]=*p;
if(*p) p++;
if(*q) q++ ;
/**********************found***********************/
k++
}
}
main( )
{ char a[10]="fshADfg",b[10]="sdAEdi",c[80]={’’/0’’};
fun(a,b,c);
printf("The string a:"); puts(a);
printf("The string b:"); puts(b);
printf("The result :"); puts(c);
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是根据整型形参m,计算如下公式的值。
y=1-1/(2×2)+1/(3×3)-1/(4×4)+…+(-1)(m+1)/(m×m)
例如:m中的值为5,则应输出0.838611。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
double fun(int m)
{ double y=1.0;
/**********************found***********************/
int j=1;
int i;
for(i=2; i<=m; i++)
{
j=-1*j;
/**********************found***********************/
y+=1/(i * i);
}
return(y);
}
main( )
{
int n=5;
clrscr( );
printf("/nThe result is %lf/n" ,fun(n));
}
[简答题]改错题
下列给定程序中,函数fun( )的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
void fun(char *s)
{
int i,j;
for(i=0,j=0; s[i]!= ’’/0’’; i++)
/**********************found***********************/
if((s[i]>= ’’A’’&&s[i]<= ’’Z’’)&&(s[i]>= ’’a’’&&s[i]<= ’’z’’))
s[j++]=s[i];
/**********************found***********************/
s[j]= "/0";
}
main( )
{
char item[80];
clrscr( );
printf("/nEnter a string: ");
gets(item);
printf("/n/nThe string is:/%s/n",item);
fun(item);
printf("/n/nThe string of changing is :/%s/n",item);
}
[多项选择]改错题
下列给定程序中,函数fun( )的功能是:从n个学生的成绩中统计出高于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
85 65.5 69 95.5 87 55 62.5 75
则高于平均分的学生人数为4(平均分为74.312500)。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#define N 20
int fun(float *s, int n,float *aver)
{
/**********************found***********************/
int ave ,t=0;
int count=0,k,i;
for(k=0;k