第章习题c(The ninth chapter exercises C).doc
文本预览下载声明
第9章习题c(The ninth chapter exercises C)
9.27 input a line of digital characters, please use array elements as counters to count the number of each number of characters. The number of characters0is counted by the element of subscript 0, and the number of the character1 is counted by subscript 1,.......
#include stdio.h
Void main ()
{
Int num[10]={0}, i;
Char ch;
Printf (input one line numeric character: \n);
While ((ch=getchar ()) - =\n)
Num[ch-0]++;
Printf (the number of characters in the input character is as follows: \n);
For (i=0; i10; i++)
If (Num)
Printf (\%c\has:%d \n,0+i, num[i]);
}
9.28 write functions, the array with 10 integers for the following operation: starting from the subscript n elements until the last element, move forward in a position. The result of moving output.
#include stdio.h
#include stdlib.h
#include time.h
#define M 10
Int fun928 (int a[], int n, int POS)
{
Int i;
For (i=pos; in; i++)
A[i]=a[i+1];
Return n-1;
}
Void arrin (int a[], int n)
{
Int i;
*
Printf (input%d data to array: \n, n);
Printf (======================================\n);
For (i=0; in; i++)
{
Printf (arr[%d]=, I);
Scanf (%d, a[i]);
}
* /
Printf (======================================\n);
Srand ((unsigned) time (NULL));
For (i=0; in; i++)
A[i]=rand ()% (100-50) +50;
}
Void arrout (int a[], int n)
{
Int i;
Printf (output%d data to array: \n, n);
Printf (======================================\n);
For (i=0; in; i++)
If ((i+1)%5)
Printf (arr[%d]=%-6d, I, a[i]);
Else
Printf (arr[%d]=%d\n, I, a[i]);
Printf (\n);
Printf (======================================\n);
}
Void main ()
{
Int arr[M], del;
Int n=M;
Arrin (arr, n);
Printf (output before shift: \n);
Arrout (arr, n);
Printf (start shift subscript:);
Scanf (%d, del);
N=fun928 (arr, N, del);
Printf (shifted output: \n);
Arrout (arr, n);
}
9.29 write the function, the array of all odd numbers in another array to return.
#include stdio.h
#define M 20
Int fun929 (int a[], int b[], int n)
{
Int i, cnt=0;
For (i=0; in; i++)
If (a[i]%2=
显示全部