c语言程序设计现代方法 源代码,C语言程序设计源代码.doc

C语言程序设计源代码.doc

第二章

L2-1a-1

main()

{

int a;

float b;

char c;

a = 1;

b = 2.5;

c = 'A';

}

L2-1a-2

main()

{

int a = 1; /* 定义整型变量a并对其初始化 */

float b = 2.5; /* 定义实型变量b并对其初始化 */

char c = 'A'; /* 定义字符型变量c并对其初始化 */

}

L2-1b

#include

main()

{

int a = 1;

float b = 2.5;

char c = 'A';

printf("a = %d\n", a); /* 按整型格式输出变量a的值 */

printf("b = %f\n", b); /* 按实型格式输出变量b的值 */

printf("c = %c\n", c); /* 按字符型格式输出变量c的值 */

printf("End of program\n"); /* 输出一行字符串 */

}

L2-2

#include

main()

{

printf("Data type Number of bytes\n");

printf("------------ ---------------------\n");

printf("char %d\n", sizeof(char));

printf("int %d\n", sizeof(int));

printf("short int %d\n", sizeof(short));

printf("long int %d\n", sizeof(long));

printf("float %d\n", sizeof(float));

printf("double %d\n", sizeof(double));

}

L2-3

#include

main()

{

float a;

double b;

a = 123456.789e4;

b = 123456.789e4;

printf("%f\n%f\n",a,b);

}

第三章

L3-1

#include

main()

{

int x, b0, b1, b2, sum;

x = 153;

b2 = x / 100; /*计算百位数字*/

b1 = (x - b2 * 100) / 10; /*计算十位数字*/

b0 = x % 10; /*计算个位数字*/

sum = b2 + b1 + b0;

printf("b2=%d, b1=%d, b0=%d, sum=%d\n", b2, b1, b0, sum);

}

L3-2

#include

main()

{

double r = 5.3; /* 圆的半径 */

double circum; /* 圆的周长 */

double area; /* 圆的面积 */

circum = 2 * 3.14159 * r; /* 计算圆的周长 */

area = 3.14159 * r * r; /* 计算圆的面积 */

printf("circumference = %f\n", circum);

printf("area = %f\n", area);

}

L3-3

#include

main()

{

double r;

double circum;

double area;

printf("Input r:"); /* 提示用户输入半径的值*/

scanf("%lf", &r); /* 从键盘输入半

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值