请补充函数fun(),该函数的功能是;删除字符数组中小于等于指定字符的字符,指定字符从键盘输入,结果仍保存
例如,输入“abcdefghij”,指定字符为‘d’,则结果输出“defghij”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio. h>
define N 80
void fun (char s[], char ch)
{
int i=0, j=0;
while (s [i] )
{
if (s Iii<ch)
【 】;
else
{
【 】
i++;
}
}
【 】
}
main ()
{
char str [N], ch;
clrscr ();
printf("\n Input a string:\n");
gets (str);
printf("\n*** original string ***\n");
puts (str);
printf("\n Input a character:\n");
scanf ("%c", &ch);
fun(str, ch);
printf("\n*** new string ***\n");
puts (str);
}
第1题
编写程序,实现矩阵(3行3列)的转置(即行列互换)。
例如,若输入下面的矩阵:
100 200 300
400 500 600
700 800 900
则程序输出:
100 400 700
200 500 800
300 600 900
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <conio.h>
int fun (int array[3][3])
{
}
main()
{
int i,j;
int array [3][3]={{100,200,300},{400,
500,600},{700,800,900}};
clrscr();
for (i-0;i<3;i++)
{for (j=0;j<3;j++)
printf("%7d ",array[i] [j]);
printf("\n ");
}
fun(array);
printf("Converted array:\n ");
for (i=0;i<3;i++)
{ for (j=0;j<3;j++)
printf("%7d ",array[i][j]);
printf("\n ");
}
}
第2题
请编写函数fun(),其功能是:计算并输出给定10个数的方差。
其中
例如,给定的10个数为95.0,89.0,76.0,65.0,88.0, 72.0,85.0,81.0,90.0,56.0,则输出为S=11.730729。
注意;部分源程序给出如下.
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<math.h>
include<stdio.h>
double fun(double x[10])
{
}
main()
{
double s,x[i0]={95.0,89.0,76.0,65.0,
88.0,72.0,85.0,81.0,90.0,56.0};
int i;
printf("\nThe original data is:\n");
for(i=0;i<10;i++)
printf("%6.1f ",x[i]);
printf("\n\n ");
s=fun(x);
printf("s=%f\n\n ",s);
}
第3题
符串。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
void fun(char *s)
{int i,j;
for(i=0,j=0; s[i]!= '\0'; i++)
if(s[i]>= '0'&&s[i]<= '9')
/*************found**************/
s[j]=s[i];
/*************found**************/
s[j]="\0";
}
main()
{char item[80];
clrscr();
printf("\nEnter a string: ");gets(item);
printf("\n\nThe string is:\%s\n", item);
fun(item);
printf("\n\nThe string of changing is :
\%s\n",item);
}
第4题
和中间的*号不删除。
例如,字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是:****A*BC*DEF*G。在编写函数时,不得使用C语言提供的字符串函数。
注意:部分源程序在文件PROGl.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第5题
下列给定程序中,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%If\n",fun(m));
}
第6题
并组成一个新的字符串。
例如,若字符串数组中的M个字符串为
AAAA
BBBBBBB
CC
则合并后的字符串内容应该是AAAABBBBBBBCC
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio. h>
define M 3
define N 20
void fun (char a [M] [N], char *b)
{
}
main ( )
{
char w [M] [N] ={"AAAA", "BBBBBBB", "CC"}, i;
char a[100]={" "};
printf ("The string: \n ");
for (i=0; i<M; i++)
puts (w[i]);
printf (" \n ");
fun (w, a);
printf ("The A string: \n ");
printf("%s ",a);
printf("\n\n ");
}
第7题
i数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include <stdio.h>
int fun(int t)
{
}
main()
{
int n;
clrscr();
n=1000;
printf("n=%d, f=%d\n",n, fun(n));
}
第8题
请编写函数fun,它的功能是:计算并输出n(包括n)以内能被5或9整除的所有自然数的倒数之和。
例如,在主函数中从键盘给n输入20后,输出为:s=0.583333。注意:要求n的值不大于100。
部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第9题
给定程序MODll.C中函数fun的功能是:根据整型形参n,计算如下公式的值。
例如,若n=10,则应输出:0.617977。
请改正程序中的语法错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
第10题
下列给定程序中,函数fun()的功能是:根据整型形参n,计算如下公式的值。
A1=1,A2=1/(1+A1),A3=1/(1+A2),…,An=(1/(1+A(n-1))
例如,若p=10,则应输出0.617977。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动mah函数,不得增行或删行,也不得更改程序的蛄构.
试题程序:
include <conio.h>
include <stdio.h>
/**************found********************/
iht fun(iht n)
{ float A=l;inti;
/**************foudn********************/
for(i=2;i<n;i++)
A=1.0/(i+A);
return A;
}
main ()
{ int n;
clrscr ();
printf("\nPlease enter n: ");
$canf ("%d", &n);
printf ("A%d=%lf\n", n, fun (n));
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!