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);
/*****************************/
}