c语言08考题2
- 格式:doc
- 大小:67.00 KB
- 文档页数:6
例如:fun1(0.76)=2.175
fun1(3.00)=5.307
fun1(3.76)=9.111
2、打开程序cprog012.c,完成其中的函数fun2(int a[],int n,int b[],int c[]),实现:
1)将数组a中大于-20的元素,依次存放到数组b中;
2)将数组b的元素按照从小到大的顺序存放到数组c中;
3)函数返回数组b中的元素个数。
Cprog011.c
#include
#include
double fun1(double x)
{ /**/
x=(1+sin(x)+exp(x))/(1+x);
return(x);
/**/
}
void main()
{
clrscr();
printf("fun1(0.76) = %8.3lf\n", fun1(0.76)); printf("fun1(3.00) = %8.3lf\n", fun1(3.00)); printf("fun1(3.76) = %8.3lf\n", fun1(3.76)); }
Cprog012.c
#include
#include
#include
#include
int fun2(int a[],int n,int b[],int c[])
{ /**/
int i,k,temp,j=0;
for (i=0;i if (a[i]>-20) b[j++]=a[i]; for (i=0;i for (i=0;i for (k=i+1;k if (c[i]>c[k]) { temp=c[i]; c[i]=c[k]; c[k]=temp; } return j; /**/ } void main() { int n = 10, i, nb; int aa[10] = {12, -10, -31, -18, -15, 50, 17, 15, -20, 20}; int bb[10], cc[10]; clrscr(); printf("There are %2d elements in aa.\n", n); printf("They are: "); for(i=0; i printf("\n"); nb = fun2(aa, n, bb, cc); printf("Elements in bb are: "); for (i=0; i printf("\n"); printf("Elements in cc are: "); for(i=0; i printf("\n"); printf("There are %2d elements in bb.\n", nb); } 如fun1(0.76)=3.582 fun1(3.00)=5.369 fun1(3.76)=8.931 2、打开程序Cprog022.c,完成其中的函数fun2(char a[] ,char b[] ,char c[] ),实现:将三个字符串a、b、c从小到大排 序后输出。 注意:字符串比较函数为strcmp(str1,str2), 字符串赋值函数为strcpy(str1,str2)。 Cprog021.c #include #include double fun1(double x) { /**/ x=(exp(x)+fabs(x-6))/(x+1.3); return x; /**/ } void main() { clrscr(); printf("fun1(0.76) = %8.3lf\n", fun1(0.76)); printf("fun1(3.00) = %8.3lf\n", fun1(3.00)); printf("fun1(3.76) = %8.3lf\n", fun1(3.76)); } Cprog022.c #include #include #include #include void fun2(char a[],char b[],char c[]) { /**/ char temp[15]; if (strcmp(a,b)>0) { strcpy(temp,a); strcpy(a,b); strcpy(b,temp); } if (strcmp(a,c)>0) { strcpy(temp,a); strcpy(a,c); strcpy(c,temp); } if (strcmp(b,c)>0) { strcpy(temp,b); strcpy(b,c); strcpy(c,temp); } /**/ } void main() { char str1[15]="Fuzhou",str2[15]="Fujian",str3[15]="China"; clrscr(); fun2(str1,str2,str3); printf("The ordered strings is : %s, %s, %s\n",str1,str2,str3); getch(); }