有以下函数,该函数的功能是()int fun(char *s){char *t=s;while(*t++);return(t-s);}
A.比较两个字符的大小
B.计算s所指字符串占用内存字节的个数
C.计算s所指字符串的长度
D.将s所指字符串复制到字符串t中
B、计算s所指字符串占用内存字节的个数
A.比较两个字符的大小
B.计算s所指字符串占用内存字节的个数
C.计算s所指字符串的长度
D.将s所指字符串复制到字符串t中
B、计算s所指字符串占用内存字节的个数
请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include <math. h>
include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}
设有以下函数 f(int a) { int b=0; static int c=3; b++;c++; return(a+b+c); } 如果在下面的程序中调用该函数,则输出结果是______。 main() { int a=2,i; for(i=0;i<3;i++)printf("%d\n"f(a)); }
A.7 8 9
B.7 9 11
C.7 10 13
D.7 7 7
以下程序中函数 f 的功能是在数组 x 的 n 个数 (假定 n 个数互不相同 ) 中找出最大最小数 , 将其中最小
的数与第一个数对换 , 把最大的数与最后一个数对换 . 请填空 .
#include <stdio.h>
viod f(int x[],int n)
{ int p0,p1,i,j,t,m;
i=j=x[0]; p0=p1=0;
for(m=0;m<n;m++)
{ if(x[m]>i) {i=x[m]; p0=m;}
else if(x[m]<j) {j=x[m]; p1=m;}
}
t=x[p0]; x[p0]=x[n-1]; x[n-1]=t;
t=x[p1]; x[p1]= _[14]_______ ; _[15]_______ =t;
}
main()
{ int a[10],u;
for(u=0;u<10;u++) scanf("%d",&a[u]);
f(a,10);
for(u=0;u<10;u++) printf("%d",a[u]);
printf("\n");
}
A.int f(int)const
B.onst int f(int)
C.int f(const int)
D.onst int f(const int)
下列程序定义了N×N的二维数组,并在主函数中自动赋值;请编写函数fun(int a[][N]),该函数的功能是:使数组左下半三角元素中的值全部置成0。例如a数组中的值为
a=1 9 7
2 3 8
4 5 6
则返回主程序后a数组中的值应为
0 9 7
0 0 8
0 0 0
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <stdlib.h>
define N 5
int fun (int a[] [N])
{
}
main()
{
int a[N] [N],i,j;
clrscr();
printf("*****The array*****\n");
for(i=0;i<N;i++)
/*产生—个随机的5*5矩阵*/
{ for(j=0;j<N;j++)
{a[i][j]=rand()%10;
printf("%4d", a[i][j]);
}
printf("\n");
}
fun (a);
printf("THE RESULT\n");
for(i=0;i<N;i++)
{ for(j=0;j<N;j++)
printf("%4d",a[i][j));
printf("\n");
}
}
请补充函数fun(),该函数的功能是:把字符下标为非素数的字符从字符串sb中删除,把字符下标为素数的字符重新保存在字符串e口中。字符串sb从键盘输入,其长度作为参数传入函数fun()。
例如,输入“abcdefghijkl”,输出“cdfhl”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun(char s[],int n)
{
int i, j, k, flag;
【 】;
for(i=0; i<n; i++)
{
if (i>1)
s [k++] =s [i];
flag=I;
for(【 】; j<i&&flag; j++)
if (i%j==0)
{
flag=0;
【 】
}
}
s [k]='\0';
}
main()
{
int i=0, strlen=0;
char str[N];
clrscr ();
printf("\n Input a string:\n");
gets (str);
while (str [i] !='\0')
{
strlen++;
i++;
}
fun (str, strlen);
printf("\n*** display string ***\n");
puts (str);
}
有以下函数定义: void fun(int n double x){…} 若以下选项中的变量都已正确定义并赋值,则对函数fun的正确调用语句是()。
A.fun(int y,double m);
B.k=fun(10,12.5);
C.fun(x,n);
D.void fun(n,x);
请编写函数fun(),该函数的功能是:移动字符串中的内容,移动的规则是把第1到第m个字符,平移到字符串的最后,把第m+1到最后的字符移到字符串的前部。
例如,字符串中原有的内容为ABCDEFGHIJK,m的值为 3,移动后,字符串中的内容应该是DEFGHIJKABC。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio. h>
include <string.h>
define N 80
void fun (char *w, int m)
{
}
main ()
{
char a[N]= "ABCDEFGHIJK";
int m;
printf ("The origina string : \n");
puts (a);
printf("\n\nEnter m: ");
scanf ("%d", &m);
fun (a, m);
printf (" \nThe string after moving : \n");
puts (a);
printf ("\n\n");
}
下面哪几个函数是public void example(){...}的重载函数()。
A. public void example(int m){...}
B. public int example(){...}
C. public void example2(){...}
D. public int example3 (int m, float f){...}