请编写函数fun,函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大
例如,一维数组中的数据是:2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10。
删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
例如,一维数组中的数据是:2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10。
删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
fun(int x,intb[])
{int k=0,r;
do
{r=x%______;
b[k++]=r;
x/=______;
}while(x);
}
请编写函数fun(),其功能是:将s所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在t所指数组中。
例如,当s所指字符串中的内容为ABCDEFGHIJK,则在t所指数组中的内容应是BDFHJ。
注意:部分源程序给出如下。
请勿改动主函数main口其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio .h>
include<string.h>
void fun(char *s,char t[])
{
}
main ()
char s[l00] ,t[l00];
clrscr ();
printf("%nPlease enter string S: ");
scanf("%s ",s);
fun(s,t);
prlntf("\nThe result is:%s\n ",t);
}
请补充函数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);
}
寻找最大数 题目内容: 主函数定义一个长度为5的整型一维数组,编写一个函数实现求此一维数组的最大值。函数 原型:int max(int a[], int n); 功能是返回长度为n的数组a中最大的一个数。 输入格式: 5个整数 输出格式: "The result is %d\n" 输入样例1: 12 6 18 9 4↙ 输出样例1: The_result_is_18 输入样例2: 9 7 -2 3 4↙ 输出样例2: The_result_is_9
下列给定程序中函数fun()的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
long fun(long num)
{
/*+**+*+*+*found************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/*********+found*+**+*+******/
}while(num)
return(k);
}
main()
{
long n;
clrscr();
printf("\Please enter a number:");
scanf("%ld",&n);
printf("\n%ld\n",fun(n));
}
下列给定程序中,函数fun()的功能是:用递归算法计算斐波拉契级数列中第n项的值。从第一项起,斐波`拉契级数序列为1, 1,2,3,5,8,13,21,……例如,若给n输入7,
该项的斐波拉契级数值为13。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
long fun(int g)
{
/*************found**************/
switch(g);
{case 0:return 0;
switch(g)
case 1; case 2:return 1;
}
return (fun(g-1)+fun(g-2));
}
main()
{
long fib; int n;
printf("Input n:");scanf("%d",&n);
printf("n-%d\n",n);
fib=fun(n);
printf("fib=%d\D\n",fib);
}
下列给定程序中,函数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);
}
A.[A] 求字符串的长度
B.[B] 比较两个字符串的大小
C.[C] 将字符串x复制到字符串y
D.[D] 将字符串x连接到字符串y后面