C语言程序中必须有的函数是().
第1题:
下列给定的程序中,函数fun()的功能是:求输入的两个数中较小的数。
例如:输入5 10,结果为rain is 5。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include <stdio.h>
#include <conio.h>
int fun(int x, (1) )
{
int z;
z=x<y (2) x:y;
return(z);
}
main()
{
int a, b, c;
scanf("%d, %d\n", (3) );
c=fun(a, b);
printf("min is %d", c);
}
答案:(1)y,z;(2)?(3)&a, &b
第2题:
A、main
B、MAIN
C、name
D、function
第3题:
以下四个程序中,完全正确的是( )。
A.#include<stdio.h>
B.#include<stdio.h> main(); main() {/*programming*/ {/*/programming/*/ printf("programming!\n");} printf("programming!\n");}
C.#include<stdio.h>
D.include<stdio.h> main() main() {/*/*programming*/*/ {/*programming*/ printf("programming!\n");} printf("programming!\n");}
第4题:
以下程序段给数组所有的元素输入数据,请选择正确答案填入。#include <stdio.h>main(){ int a[10],j=0; while(i<10)scanf("%d", ______ ); : :}
A.a+(i++)
B.&a[i+1]
C.a+ i
D.&a[++i]
第5题:
下列给定程序中函数fun()的功能是:计算n!。例如,给 n输入5,则输出120.000000。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
double fun (int n)
{ double result=l.0;
/*************found**************/
if n==0
return 1.0;
while (n>l&&n<170)
/*************found**************/
result *=n--
return result;
}
main ( )
{ int n;
printf ("Input N: ");
scanf ( "%d" &n);
printf ("\n\n%d!=%lf\n\n",n, fun(n));
}
第6题:
请补充main函数,该函数的功能是:从键盘输入一个长整数,如果这个数是负数,则取它的绝对值,并显示出来。
例如,输入:-3847652,结果为:3847652。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
main()
{
long int n;
clrscr();
printf("Enter the data;\n");
scanf(【 】);
printf("*** the absolute value ***\n");
if(n<0)
【 】
printf("\n\n");
printf(【 】);
}
第7题:
下列给定程序中,函数fun()的功能是:实现两个整数的交换。例如给a和b分别输入60和65,输出为:a=65 b=60
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序;
include<stdio.h>
include <conio.h>
/*************found**************/
void fun(int a,b)
{ int t;
/*************found**************/
t=b;b=a;a=t;
}
main()
{ int a,b;
clrscr();
printf("Enter a, b: "); scanf("%d%d",
&a,&b);
fun(&a, &b);
printf("a=%d b=%d\n ", a,b);
}
第8题:
下列给定的程序中,函数fun()的功能是:求输入的两个数中较小的数。
例如:输入5 10,结果为min is 5。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
include <stdio.h>
include <conio.h>
int fun(int x, (1) ;
int z;
z=x<y (2) x:y;
return(z);
}
main()
int a, b, c;
scanf("%d, %d\n", (3) );
c=fun(a, b);
printf("min is%d:, c);
}
第9题:
编写函数fun(),函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。
S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如:若n的值为11时,函数的值为1.833333。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
float fun(int n)
{
}
main()
{
int n;
float s;
clrscr();
printf("\nPlease enter N: ");
scanf("%d",&n);
s=fun(n);
printf("The result is:%f\n " , s);
}
第10题:
若执行下列程序时从键盘上输入2,则输出结果是( )。
#inclUde<stdio.h>
main()
{int a;
scanf("%d",&A);
if(a++<3)
printf("%d\n",A);
else printf("%d\n",a--);
}
A.1
B.3
C.2
D.4