问答题
请编写一个函数unsigned fun (unsigned w),w 是一个大于 10的无符号整数,若w是n(n≥2)位的整数,则函数求出w的后 n-1位的数作为函数值返回。
例如:w值为5923,则函数返回923;若w值为923,则函数返回23。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
#include<conio. h>
#include<stdio. h>
unsigned fun(unsigned w)
main()
unsigned x;
clrscr ();
printf("Enter a unsigned integer
number: ");
scanf ("%u",&x);
printf("The original data is:%u\n",x);
if (x<10)
printf ("Data error! ");
else
printf ("The result :%u\n", fun(x) );
【参考答案】
unsigned fun (unsigned w)
{
if(w>=10000)
......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
填空题
下列给定程序中,函数fun()的功能是;计算函数 F(x, y ,z)=(x+ y) (x-y)+(z+ y) (z-y)的值。其中x和y不相等,z和y不等。例如,当x的值为9,y的值为11,2的值为15时,函数值为-3.50。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include <stdio. h> #include <math. h> **************found****************** #define FU(m, n) (m n) float fun(float a, float b, float c) float value; value=FU(a+ b, a-b)+FU(c+ b, c-b); *************found****************** return(Value); main() float x, y, z, sum; printf ( Input x y z:: ); scanf( %f%f%f , &x, &y, &z); printf( x=%f, y=%f, z=%f n ,x, y, z); if (x==y||y==z) printf ( Data error! n ); exit (0); sum=fun (x, y, z); printf( The result is:%5. 2f n ,sum);
点击查看答案&解析
填空题
请补充main 函数,该函数的功能是:先以只写方式打开文件“out99.dat”,再把字符串str中的字符保存到这个磁盘文件中。 注意:部分源程序给出如下。 请勿改动主函数main 和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio. h #include conio.h #define N 80 main () FILE *fp; int i=0; char ch; char str[N]= I’m a student! ; clrscr(); if ( (fp=fopen ( 【1】 ) ) ==NULL) printf( cannot open out99. dat n ); exit(0); while (str[i]) ch=str[i]; 【2】 ; putchar(ch); i++; 【3】 ;
点击查看答案&解析
相关试题
下列给定程序中,函数fun()的功能是;计...
请补充main 函数,该函数的功能是:先以只...