程序设计与算法 第一周测验

1 十进制数255表示成四位十六进制形式是:
00FF

2 short类型变量n的值是-12,那么其值的四位十六进制形式是:
FFF4

3 有两个变量a和b,在执行了如下代码后: a = 32768; b = a; printf(“%d %d\n”, a, b); 输出两个数:32768 -32768。 请问a和b分别是以下哪种类型?

#include <stdio.h>
int main(void)
{
    unsigned short a1;
    short b1;
    int a2;
    short b2;
    unsigned int a3;
    int b3;
    a1 = 32768;
    b1 = a1;
    a2 = 32768;
    b2 = a2;
    a3 = 32768;
    b3 = a3;
    printf("%d %d\n", a1, b1);
    printf("%d %d\n", a2, b2);
    printf("%d %d\n", a3, b3);
    return 0;
}

unsigned short,short
int,short

4 编程题1: 输出第二个整数

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  printf("%d\n", b);
  return 0;
}

5 编程题2: 字符菱形:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  char in;
  int r, c;
  int m[5][5] = { {0,0,1,0,0}, {0,1,1,1,0}, {1,1,1,1,1}, {0,1,1,1,0}, {0,0,1,0,0}};
  scanf("%c", &in);
  for (r=0; r<5; r++)
  {
    for (c=0; c<5; c++)
    {
      if (m[r][c]==0)
        printf(" ");
      else
        printf("%c", in);
    }
    printf("\n");
  }
  return 0;
}

6 编程题3: 打印ASCII码:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int c;
  scanf("%c", &c);
  printf("%d\n", c);
  return 0;
}

7 编程题4:打印字符:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int i;
  scanf("%u", &i);
  printf("%c\n", i);
  return 0;
}

8 编程题5: 整型数据类型存储空间大小:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int i=0;
  short s=0;
  printf("%d %d\n", sizeof(i), sizeof(s));
  return 0;
}

4 2

9 编程题6: 浮点型数据类型存储空间大小:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  float f=0;
  double d=0;
  printf("%d %d\n", sizeof(f), sizeof(d));
  return 0;
}

4 8

-eof-

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值