更多"下列给定程序中,函数proc( )的功能是:根据整型形参n,计算如下公"的相关试题:
[简答题]下列给定程序中,函数fun( )的功能是:根据以下公式求n的值,并作为函数值返回。例如,给指定精度的变量eps输入 0.0005时,应当输出Pi=3.140578。
n/2=1+1/3+1/3*2/5+1/3*2/5*3/7+1/3*2/5*3/7*4/9……
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <math.h>
double fun(double eps)
double s,t; int n=t;
s=0.0;
/*************found**************/
t=1;
/*************found**************/
while(t>eps)
s+=t;
t=t*n/(2*n+1);
n++;
/*************found**************/
return (s);
main( )
double x;
printf("/nPlease enter a precision: ");
scanf("%1f",&x);
printf("/nPi=%1f/n ",fun(x));
[简答题]下列给定程序中,函数fun的功能是:有N×N矩阵,根据给定的m(mc=N)值,将每行元素中的值均向右移动m个位置,左位置为O。例如,N=3,m=2,有下列矩阵:
1 2 3
……
4 5 6
……
7 8 9
程序执行结果为:
0 0 1
……
0 0 4
……
0 0 7
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#define N 4
void fun(inf(*f)[N].int m)
int i,j;
/********found********/
for(i=0;i<N; (1) )
for(j=N-1-m;j>=0;j--)
/********found********/
t[i][j+ (2) ]=[i][j];
/********found********/
for(j=0;j< (3) ;j++)
t[i][j]=0;
main( )
int t[][N]=21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10,i,j,m;
printf("/nThe original array:/n");
for(i=0;i<N;i++)
for(j=0;j<N;j++)
printf("%2d",t[i][j]);
printf("/n");
printf("Input m(m<=%d):"N);
scanf("%d",&m);
fun(t,m);
printf("/nThe result is:/n");
for(i=0;i<N;i++)
fo
[简答题]改错题
下列给定程序中,函数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( )的功能是:找出一个大于给定整数m且紧随m的素数,并作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio.h>
int fun( int m)
{ int i,k;
for (i=m+1; ;i++)
{ for (k=2;k<i;k++)
/*************found**************/
if (i%k!=0)
break;
/*************found**************/
if (k<i)
return(i);
}
}
main( )
{ int n;
clrscr ( );
printf("/nPlease enter n: ");
scanf ("%d", &n);
printf ("%d/n",fun(n));
}
[简答题]下列给定程序中,函数fun的功能是:求两个非零正整数的最大公约数,并作为函数值返回。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
int fun(int a, int b)
int r, t;
if(a<b)
t=a; b=a; a=t;
/******************found*******************/
r=a%b;
while(r!=0)
a=b; b=r; r=a%b;
/******************found*******************/
return(a);
void main( )
int num1, num2, a;
printf("Input num1 num2:");
scanf("%d%d", &num1, &num2);
printf("num1=%d num2=%d/n/n", num1, num2);
a=fun(num1, num2);
printf("The maximun common divisor is%d/n/n",a);
[填空题]下列给定程序中,函数fun( )的功能是:根据整型参数m,计算如下公式的值。
y=1/(100×100)+1/(200×200)+1/(300×300)+…+1/(m×m)
例如,若m=2000,则应输出0.000160。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio. h>
/*************found**************/
fun (int m)
{ double y=0, d;
int i;
/*************found**************/
for (i=100, i<=m, i+=100)
{d= (double) i* (double) i;
y+=l. 0/d;
}
return (y);
}
main ( )
{ int n=2000;
clrscr( );
printf("/nThe result is %lf/n",fun(n));
[填空题]下列给定程序中,fun( )函数的功能是:根据形参m,计算下列公式的值。
t=-1+1/2+1/3+1/4+…+1/m
例如,若输入5,则应输出2.283333。
请改正程序中的错误,使它能计算出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
double fun(int m)
double t=1.0;
int i;
for(i=2;i<=m;i++)
/*************found**************/
t+=1.0/k;
/*************found**************/
return i;
main( )
int m;
clrscr( );
printf("/nPlease enter linteger number:");
scanf("%d",&m);
printf("/nThe result is%1f/n", fun(m));
[填空题]下列给定程序中函数fun的功能是:把从主函数中输入的3个数,最大的数放在a中,中间的数放在b中,最小的数放在C中。
例如,若输入的数为:55 12 34,输出的结果应当是.a=55.0,b=34.0,c=12.0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
void fun(float*a,float*b,float*c)
/*********found*********/
float*k;
if(*a<*b)
k=*a:
*a=*b:
*b=k;
/*********found*********/
if(*a>*c)
k=*c:
*c=*a:
*a=k;
if(*b<*c)
k=*b;
*b=*c;
*c=k;
void main( )
float a,b,c;
printf("Input a b c:");
scanf("%f%f%f",&a,&b,&c);
printf("a=%4.1f,b=%4.1f,c=%4.1f/n/n",a,b,c);
fun(&a,&b,&c);
printf("a=%4.1f,b=%4.1f,c=%4.1f/n/n",a,b,c);
[填空题]下列给定程序中,proc( )函数的功能是:根据形参m,计算下列公式的值。
t=1+1/2+1/3+1/4+…+1/m
例如,若输入10,则应输出2.928968。请修改程序中的错误,使它能计算出正确的结果。
注意:不要改动main( )函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
double proc(int m)
{
double t=1.0;
int i;
for(i=2;i<=m;i++)
//****found****
t+=1.0/k;
//****found****
return i;
}
void main( )
{ int m;
system("CLS");
printf("/nPlease enter integer number:");
scanf("%d",&m);
printf("/nThe result is%1f/n",proc(m));
}
[填空题]下列给定程序中,函数fun( )的功能是:根据输入的3个边长(整型值),判断能否构成三角形:若能构成等边三角形,则返回3,若是等腰三角形,则返回2,若能构成三角形则返回1,若不能,则返回0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <math. h>
int fun(int a, int b, int c)
{ if (a+b>c&&b+c>a&&a+c>b)
{ if (a==b&&b==c)
/*************found**************/
return 1;
else if(a==b|| b==c||a==c)
return 2;
/*************found**************/
else return 3;
}
else return 0;
}
main ( )
{ int a,b, c, shape;
printf("/nInput a,b,c: ");
scanf ("%d%d%d", &a, &b, &c);
printf ("/na=%d, b=%d, c=%d/n",a,b,c);
shape=fun (a,b, c);
printf ("/n/nThe shape : %d/n", shape);
}
[填空题]下列给定程序中,fun( )函数的功能是:根据形参m,计算下列公式的值。
t=1-1/2+1/3-1/4+…+(-1)(m+1)/m
例如,若输入5,则应输出0.783333。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
/*************found*************/
int fun(int m)
double t=1.0,j=1.0;
int i;
/*************found*************/
for(i=l;i<m;i++)
j=-1*j;t+=j/i;
return t;
main( )
int m;
clrscr( );
printf("/nPlease enter 1 integer number:");
scanf("%d",&m);
printf("/nThe result is%1f/n",fun(m));
[简答题]下列给定程序中,函数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));
[简答题]给定一个函数,其函数功能为:使10个整数按由小到大的顺序排列。在主函数中输入10个数,并输出结果。使用VC6打开考生文件夹下的工程RevProj5。此工程包含一个源程序文件RevMain5.cpp,该程序实现上述功能。但此程序运行有问题。请找出错误的地方,改正后将此程序调试正确。
注意:不得删行或增行,也不得更改程序结构。
文件RevMain5.cpp中的程序清单如下:
//RevMain5.cpp
#include<iostream>
#include<iomanip>
using namespace std;
int main( )
{
void sort(int array[],int n);
int data[10],*p,i;
cout<<"Input 10 numbers/n";
for (i=0; i<10; i++)
cin>>data [i];
cout<<"the origined array is:";
for (p=data;p<data+10;p++)
{
if((p-&data[0]) %5==0)
cout<<" /n";
cout<<setw (5) <<*p;
}
sort (data, 10);
cout<<"/n the present array is:";
for(p=data;p〈data+10;p++)
{
if((p-&data[0])%5==0) cout<<"/n";
cout<<setw (5)<<*p;
}
}
void sort(int array[],int n)
{
/* * * * * * * * *found * * * * * * * * * */
for(p1=array;p1<array+(n-1) ;p1++)
{
for (p2=p1+1 ;p2<array+n;p2++)
{
if (*p1>*p2)
{
/* * * * * * * * *found * * * * * * * * * */
[简答题]下列给定程序中,函数fun的功能是:计算并输出high以内最大的10个素数的和。high的值由主函数传给fun函数。
例如,若high的值为10。,则函数的值为732。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<scdio.h>
#include<math.h>
int fun(int high)
int sum=0,n=0,j,yes;
/********found********/
while((high>=2)&&(n<10)
yes=1;
for(j=2;j<=high/2;j++)
if(high%j==0)
/********found********/
yes=0;break
if(yes)
sum+=high;
n++;
high--;
return sum;
main( )
printf("%d/n",fun(100));