更多"下列给定程序中,函数fun的功能是:计算整数n的阶乘。 请改正程序中"的相关试题:
[填空题]下列给定程序中,函数fun的功能是:计算整数n的阶乘。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<stdio.h>
double fun(int n)
double result=1.0;
while(n>1&&n<170)
/*********found************/
result*=--n;
/***********found*********/
Return;
voidmain( )
int n;
system("CLS");
printf("Enter an integer:");
scanf("%d",&n);
printf("/n/n%d!=%1d/n/n",n,fun(n));
[填空题]下列给定程序中,函数fun( )的功能是:计算整数n的阶乘。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
double fun(int n)
double result=l.0;
whil (n>l&&n<170)
/**************found********************/
result*=--n;
/**************found********************/
return;
main( )
int. n;
clrscr( );
printf("Enter an integer: ");
scanf("%d",&n);
printf("/n/n%d!=%lg/n/n ",n, fun(n));
[简答题]请编写一个函数fun( ),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)之和(规定n的值不大于1000)。
例如:输入n的值为856,则输出为sum=763。
注意:部分源程序已存在文件test33_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数count的花括号中填写若干语句。
文件test33_2.cpp清单如下:
#include<stdio. h>
#include<iostream. h>
int fun(int n)
{
}
void main ( )
{
int n, sum;
cout<<"Input n:"<<end1;
cin>>n;
sum=fun (n);
cout<<" sum= /n"<<sum<<end1;
}
[简答题]请编写一个函数fun( ),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)的平方和(规定n的值不大于100)。
例如:主函数从键盘给输入n的值为56,则输出为 sum=1113。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
long fun(int n)
main( )
int n;
long sum;
printf("Input n:");
scanf("%d",&n);
sum=fun(n);
printf("sum=%ld/n",sum);
[简答题]下列给定程序中,函数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( )的功能是:从字符串s中,删除所有大写字母’F’。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
void fun(char *s)
{
int i, j;
/*************found**************/
for(i=j=0; s[i]!= ’0’;i++)
if(s[i] != ’F’)
/*************found**************/
s[j]=s[i];
s[j]=’/0’;
}
main ( )
{
char s[80];
printf("/nEnter a string: ");
gets(s);
printf("The original string: ");
puts(s);
fun(s);
printf("The string after deleted: ");
puts(s);
printf("/n/n ");
}
[填空题]下列给定程序中,函数fun( )的功能是:从字符串s中,删除所有小写字母’c’。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构.
试题程序:
# include <stdio.h>
void fun(char *s)
{int i, j;
for(i=j=0; s[i] != ’/0’;i++)
if(sill != ’c’)
/********************************/
s [j] =s [i];
/**************found*************/
s[i]=’/0’;
}
main ( )
{ char s[80];
printf ("/nEnter a string: ");
gets (s);
printf("The original string: ")
puts (s);
fun (s);
printf("The string after deleted: ");
puts (s); printf ("/n/n "):
}
[简答题]下列给定程序中,函数fun的功能是:用冒泡法对6个字符串进行升序排列。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdlib.h >
#include <string.h>
#include <conio.h>
#include <stdio.h>
#define MAXLINE 20
fun (char * pstr[6])
int i, j;
char * p;
for(i=0; i<5; i++)
/********** found********** /
for(j=i+1, j<6, j++)
if (strcmp (* (pstr+i), (pstr+
j))>0)
p=* (pstr+i);
/********** found********** /
* (pstr+i)=pstr+j;
* (pstr+j)=p;
void main ( )
int i;
char * pstr[6], str[6] [MAXLINE];
system ("CLS");
for(i=0; i<6; i++)
pstr[i]=str[i];
printf("/nEnter 6 string(1 string
at each line) :/n ");
for(i=0; i<6; i++)
scanf("% s", pstr[i]);
fun (pstr);
printf (" The strings after sor-
ting:/n ");
for (i=0; i<6; i++)
printf ("% s/n ", pstr[i])
[简答题]下列给定程序中,函数fun的功能是:用冒泡法对6个字符串按由小到大的顺序排列。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#define MAXLINE 20
fun(char*pstr[6])
lnt i,j;
char *p;
for(i=O;i<5;i++)
/********found********/
for(j=i+l,j<6,j++)
if(strcmp(*(pstr+i)*(pstr+j))>0)
P=*(psfr+i);
/********found********/
*(pstr+i)=pstr+j;
*(pstr+j)=p;
void main( )
int i;
char*pstr[6],str[6][MAXLINE];
system("CLS");
for(i=O;i<6;i++)
pstr[i]=str[i];
printf("/nEnter 6 string(1 string at eachline):/n");
for(i=0;i<6;i++)
scanf("%s",pstr[i]);
fun(pstr);
printf("The strings after sorting:/n");
for(i=O;i<6;i++)
printf("%s/n"pstr[i]);
[填空题]下列给定程序中fun( )函数的功能是:将n个无序整数从小到大排序。
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
fun(int n, int *a)
{ int i,j,p,t;
for (j=0;j<n-1;j++)
{ P=j;
/***************found*******************/
for(i=j+l;i<n-1;i++)
if (a[p]>a[i])
/***************found*******************/
t=i;
if (p!=j)
{t=a[j];a[j]=a[p];a[p]=t;}
}
}
putarr( iht n,int *z)
{int i;
for (i=l;i<=n;i++,z++)
{ printf("%4d",*z);
if (!(i%10)) printf("/n");
} printf ("/n");
}
main ( )
{int aa[20]={9,3,0,4,1,2,5,6,8,10,7},n=11;
clrscr( );
printf("/n/nBefore sorting %d numbers:/n",n); putarr(n,aa);
fun(n,aa);
printf("/nAfter sorting %d numbers:/n",n);putarr(n,aa);
}
[填空题]下列给定程序中,函数fun( )的功能是:从字符串s中,删除所有大写字母’F’。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
void fun(char *s)
int i, j;
/*************found**************/
for(i=j=0; s[i]!= ’0’;i++)
if(s[i] != ’F’)
/*************found**************/
s[j]=s[i];
s[j]=’/0’;
main ( )
char s[80];
printf("/nEnter a string: ");
gets(s);
printf("The original string: ");
puts(s);
fun(s);
printf("The string after deleted: ");
puts(s);
printf("/n/n ");
[填空题]下列给定程序中,函数fun( )的功能是:从字符串s中,删除所有小写字母’c’。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构.
试题程序:
# include <stdio.h>
void fun(char *s)
int i, j;
for(i=j=0; s[i] != ’/0’;i++)
if(sill != ’c’)
/********************************/
s [j] =s [i];
/**************found*************/
s[i]=’/0’;
main ( )
char s[80];
printf ("/nEnter a string: ");
gets (s);
printf("The original string: ")
puts (s);
fun (s);
printf("The string after deleted: ");
puts (s); printf ("/n/n "):