if(totCnt) totPjz/=totCnt;
/**/
}
类似题一、编制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个 正整数totNum; 2. 求这些数右移1位后, 产生的新数是偶数的数 的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平 均值totPjz。
void Calvalue(void)
{/**/
for(; xx[totNum]>0; totNum++)
if((xx[totNum]>>1)%2==0)
{ totCnt++; totPjz+=xx[totNum]; }
if(totCnt) totPjz/=totCnt;
/**/
类型题六
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到 字符串数组xx中; 请编制函数SortCharD( ), 其函数的功能是: 以行为单位对字符按从大到小的顺序进行排序, 排序后的结果仍按行
重新存入字符串数组xx中。最后main()函数调用函数WriteDat()把 结果xx输出到文件OUT2.DAT中。 例: 原文: dAe,BfC.
CCbbAA
结果: fedCBA.,
bbCCAA
char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */
void SortCharD(void)
{/**/
int i,j,k,m,n; char ch;
for(i=0; i < maxline; i++)
{ j=strlen(xx[i]); /*求出每行的字符个数*/
for(m=0; m < j-1; m++)
{ for(n=m+1; n < j; n++)
if(xx[i][m] < xx[i][n])
{ ch=xx[i][m]; xx[i][m]=xx[i][n]; xx[i][n]=ch; }