练习9程序利用函数 insert(向一组有序的数中插入一 个数X,请编写 inserte()函数。 #definen 11 void insert(int al l,int x, int n) void maino inta[N|={2,6,11,15,19,24,30,33,40,55}; int x: int i: printf("Please input x scanf(%d", &x) insert(a, X, N); for(i=0:i<n: i++ printf(od aiD; printf("Ⅶn");}
练习9程序利用函数insert( ) 向一组有序的数中插入一 个数x,请编写insert( )函数。 #define N 11 void insert(int a[ ],int x, int n) { } void main( ) {int a[N]={2,6,11,15,19,24,30,33,40,55}; int x; int i; printf("Please input x:"); scanf("%d",&x); insert(a,x,N); for (i = 0 ; i < N ; i++) printf("%d ",a[i]); printf("\n"); }
void insert(int all,int x, int n) int location: /应插入的位置 int ∥)定位 for(location=0; allocation< x & location <(n-1); location++); ∥移动元素 for(i=n-1; location i--) a=ai-1; 插入数 a location
void insert(int a[],int x,int n) { int location; //x应插入的位置 int i; //定位 for(location=0; a[location] < x && location < (n-1); location++); //移动元素 for (i=n-1;i>location ; i- -) a[i] = a[i-1]; //插入数 a[location] = x; }
练习10程序利用函数 count()统计输入的一个字符串中 包含多少个单词,请编写 count(函数。 #include stdio. h int count(char strD void main() char str[100; int wordcount. gets(str); wordcount=count(str); printf( The Number of word is %d \n", wordcount);
练习10 程序利用函数count( )统计输入的一个字符串中 包含多少个单词,请编写count( )函数。 #include "stdio.h" int count(char str[]) { } void main( ) { char str[100]; int wordcount; gets(str); wordcount = count(str); printf("The Number of word is %d\n",wordcount); }