WEEK4 C 作业

1 输入一行字符,分别统计出其中字母,空格,数字和其他字符的个数

#include <stdio.h>

void main()

{

 int letter, space, num, other;

 char ch;

 letter = space = num = other = 0;

 while ((ch = getchar ()) != '\n')

 {

  if (ch>='a' && ch <= 'z' || ch>='A'&&ch<='Z')

   letter++;

  else if (ch>='0' && ch <='9')

num++;

  else if (ch == ' ')

   space++;

  else

   other++;

 }

 printf ("字母:%d\n", letter);

 printf ("空格:%d\n", space);

 printf ("数字:%d\n", digit); \

 printf ("其它字符:%d\n", other);

}

WEEK4 C 作业 

2 求下列式子的值:1-1/2+1/3-1/4+……+1/99-1/100,将结果输出

#include<stdio.h>

int main()

{int i,k;

double sum,f;

sum=1.0;

k=1;

for(i=2;i<=100;i++)

{

k=-k;

f=1.0/i;

sum=sum+k*f;

}printf("%.f\n",sum);

return 0;

}

WEEK4 C 作业3 矩阵转置:将一个mn列矩阵(M*N矩阵)的每一行转置成另一个N*M矩阵的相应列:
例如:2*3的矩阵转置后输出:

#include<stdio.h>

Int main()

{
int a [2][3].j.k.b[3][2];

For(i=0;j<2;j++)

For(k=0;k<3;k++)

Scanf(%d,&a[j][k]);

For(i=0;j<2;j++)

For(k=0;k<3;k++)

b[j][k]=a[k][j]

For(i=0;j<2;j++)

{printf(%d\n,a[j][k]);

Printf(%d\n,b[k][j]

}

Return 0

}

有点懵...