二级题库23.

1.#include  <stdio.h>
#include  <string.h>
#define   N   5
#define   M   8
void fun(char  (*ss)[M])
{ char  *ps[N],*tp;    int  i,j,k;
  for(i=0; i<N; i++) ps[i]=ss[i];
  for(i=0; i<N-1; i++) {
/**********found**********/
    k= i ;
    for(j=i+1; j<N; j++)
/**********found**********/
       if(strlen(ps[k]) < strlen(ps[j]) ) k=j;
/**********found**********/
    tp=ps[i];  ps[i]=ps[k]; ps[k]= tp ;
  }
  printf("\nThe string after sorting by length:\n\n");
  for(i=0; i<N; i++)  puts(ps[i]);
}
void main()
{ char  ch[N][M]={"red","green","blue","yellow","black"};
  int  i;
  printf("\nThe original string\n\n");
  for(i=0;i<N;i++)puts(ch[i]);  printf("\n");
  fun(ch);
}

2.#include <stdlib.h>
#include  <conio.h>
#include  <stdio.h>
#include  <math.h>
/*************found**************/
double fun(int n)  
{double sum, s0, s1, s2, s; int k;
 sum=1.0;
 if (n<=2) sum=0.0;
 s0=0.0; s1=0.0; s2=1.0;
 for (k=4;k<=n;k++)
    { s=s0+s1+s2;
      sum+=sqrt(s);
      s0=s1;s1=s2;s2=s;
    }
/*************found**************/
 return sum;
}
void main()
{int n;
 system("CLS");
 printf("Input  N=");
 scanf("%d",&n);
 printf("%f\n",fun(n));
}

3.#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
double fun(double x, int n)
{
  int i;

double s=1.0,s1=1.0;

for(i=0;i<=n;i++)

{
s1=s1*i;

s=s+spow(x,i)/s1;

}
}
void main()

  FILE *wf;
  system("CLS");
  printf("%f ",fun(0.3,10));
/******************************/
  wf=fopen("out.dat","w");
  fprintf(wf,"%f",fun(0.3,10));
  fclose(wf);
/*****************************/
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值