10.22C语言笔试题

1、#include <stdio.h>
void main()
{
 int letter, space, digit, other;
 char ch;
 letter = space = digit = other = 0;
 while ((ch = getchar ()) != '\n')//检查是否到了数组结束后最后一个空格
 {
  if (ch>='a' && ch <= 'z' || ch>='A'&&ch<='Z')
   letter++;
  else if (ch>='0' && ch <='9')
   digit++;
  else if (ch == ' ')
   space++;
  else
   other++;
 }
 printf ("字母:%d\n", letter);
 printf ("空格:%d\n", space);
 printf ("数字:%d\n", digit);
 printf ("其它字符:%d\n", other);
 getch();
}
10.22C语言笔试题
2、求下列试子的值:1-1/2+1/3-1/4+……+1/99-1/100,将结果输出。

#include<stdio.h>
int main()
{
 int a=1;
 int b=2.0,c=1.0,d;
 while (b<=100)
 {
  a=-a;
  d=a/b;
  sum=sum+d;
  b=b+1;
 }
 printf("%f\n",sum);
 return 0;
}
10.22C语言笔试题
3、矩阵转置:将一个m行n列矩阵(即m×n矩阵)的每一行转置成另一个n×m矩阵的相应列
   例如:将2*3的矩阵转置后输出:

#include <stdio.h>
int main()
{
int a[4][3];
int i,j;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
scanf("%d",&a[j][i]);
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
printf("%d ",a[i][j]);
printf("\n");
}
return 0;
}