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();
}

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;
}
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值