c语言 int -65537,程序设计基础(C)第03讲例程

3.1 platinum.c

/* platinum.c -- your weight in platinum */

#include

int main(void)

{

float weight; /* 你的体重 */

float value; /* 相等重量的白金价值 */

printf("Are you worth your weight in platinum?\n");

printf("Let's check it out.\n");

printf("Please enter your weight in pounds: ");

/* 获取用户的输入 */

scanf("%f", &weight);

/* 假设白金的价格是每盎司$1700 */

/* 14.5833 用于将英镑常衡盎司转换为金衡盎司```*/

value = 1700.0 * weight * 14.5833;

printf("Your weight in platinum is worth $%.2f.\n", value);

printf("You are easily worth that! If platinum prices drop,\n");

printf("eat more to maintain your value.\n");

return 0;

}

3.2 print1.c

/* print1.c-演示printf()的一些特性 */

#include

int main(void)

{

int ten = 10;

int two = 2;

printf("Doing it right: ");

printf("%d minus %d is %d\n", ten, 2, ten - two );

printf("Doing it wrong: ");

printf("%d minus %d is %d\n", ten ); // 错误,遗漏了两个参数

return 0;

}

3.3 bases.c

/* bases.c--以十进制、八进制、十六进制打印十进制数100*/

#include

int main(void)

{

int x = 100;

printf("dec = %d; octal = %o; hex = %x\n", x, x, x);

printf("dec = %d; octal = %#o; hex = %#x\n", x, x, x);

return 0;

}

3.4 print2.c程序

/* print2.c-更多printf() 特性 */

#include

int main(void)

{

unsigned int un = 3000000000; /* int为32位的系统 */

short end = 200; /* short为16位的系统 */

long big = 65537;

long long verybig = 12345678908642;

printf("un = %u and not %d\n", un, un);

printf("end = %hd and %d\n", end, end);

printf("big = %ld and not %hd\n", big, big);

printf("verybig= %lld and not %ld\n", verybig, verybig);

return 0;

}

3.5 charcode.c

/* charcode.c-显示字符的代码编号 */

#include

int main(void)

{

char ch;

printf("Please enter a character.\n");

scanf("%c", &ch); /* 用户输入字符 */

printf("The code for %c is %d.\n", ch, ch);

return 0;

}

3.6 altnames.c

/* altnames.c -- 可移植整数类型名 */

#include

#include // 支持可移植类型

int main(void)

{

int32_t me32; // me32 是一个32位有符号整型变量

me32 = 45933945;

printf("First, assume int32_t is int: ");

printf("me32 = %d\n", me32);

printf("Next, let's not make any assumptions.\n");

printf("Instead, use a \"macro\" from inttypes.h: ");

printf("me32 = %" PRId32 "\n", me32);

return 0;

}

3.7showf_pt.c

/* showf_pt.c -- 以两种方式显示float类型的值 */

#include

int main(void)

{

float aboat = 32000.0;

double abet = 2.14e9;

long double dip = 5.32e-5;

printf("%f can be written %e\n", aboat, aboat);

//下一行要求编译器支持c99或其中的相关特性

printf("And it's %a in hexadecimal, powers of 2 notation\n", aboat);

printf("%f can be written %e\n", abet, abet);

printf("%Lf can be written %Le\n", dip, dip);

return 0;

}

3.8 typesize.c

//* typesize.c -- 打印类型大小为类型大小提供%zd的转换说明 */

#include

int main(void)

{

/* c99为类型大小提供%zd的转换说明 */

printf("Type int has a size of %zd bytes.\n", sizeof(int));

printf("Type char has a size of %zd bytes.\n", sizeof(char));

printf("Type long has a size of %zd bytes.\n", sizeof(long));

printf("Type long long has a size of %zd bytes.\n",sizeof(long long));

printf("Type double has a size of %zd bytes.\n",sizeof(double));

printf("Type long double has a size of %zd bytes.\n",sizeof(long double));

return 0;

}

3.10 escape.c

/* escape.c -- 使用转义序列 */

#include

int main(void)

{

float salary;

printf("\aEnter your desired monthly salary:");/* 1 */

printf(" $_______\b\b\b\b\b\b\b"); /* 2 */

scanf("%f", &salary);

printf("\n\t$%.2f a month is $%.2f a year.", salary,salary * 12.0); /* 3 */

printf("\rGee!\n"); /* 4 */

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值