c语言troubc int类型占几个字节,程序设计基础(C)第06讲例程
1summing.c
/* summing.c -- 根据用户键入的整数求和 */
#include
int main(void)
{
long num;
long sum = 0L; /* 把sum 初始化为0 */
int status;
printf("Please enter an integer to be summed ");
printf("(q to quit): ");
status = scanf("%ld", &num);
while (status == 1) /* == means "is equal to" */
{
sum = sum + num;
printf("Please enter next integer (q to quit): ");
status = scanf("%ld", &num);
}
printf("Those integers sum to %ld.\n", sum);
return 0;
}
2 when.c
// when.c -- 何时退出循环
#include
int main(void)
{
int n = 5;
while (n < 7) // line 7
{
printf("n = %d\n", n);
n++; // line 10
printf("Now n = %d\n", n); // line 11
}
printf("The loop has finished.\n");
return 0;
}
3 while1.c
/* while1.c -- 注意花括号的使用 */
/* 糟糕的代码创建了一个死循环 */
#include
int main(void)
{
int n = 0;
while (n < 3)
printf("n is %d\n", n);
n++;
printf("That's all this program does\n");
return 0;
}
4 while2.c
/* while2.c -- 注意分号的位置 */
#include
int main(void)
{
int n = 0;
while (n++ < 3); /* line 7 */
printf("n is %d\n", n); /* line 8 */
printf("That's all this program does.\n");
return 0;
}
5 cmpflt.c
// cmpflt.c -- 浮点数比较
#include
#include
int main(void)
{
const double ANSWER = 3.14159;
double response;
printf("What is the value of pi?\n");
scanf("%lf", &response);
while (fabs(response - ANSWER) > 0.0001)
{
printf("Try again!\n");
scanf("%lf", &response);
}
printf("Close enough!\n");
return 0;
}
6 t_and_f.c
/* t_and_f.c -- C中的真和假的值 */
#include
int main(void)
{
int true_val, false_val;
true_val = (10 > 2); // value of a true relationship
false_val = (10 == 2); // value of a false relationship
printf("true = %d; false = %d \n", true_val, false_val);
return 0;
}
7 truth.c
// truth.c -- 哪些值为真
#include
int main(void)
{
int n = 3;
while (n)
printf("%2d is true\n", n--);
printf("%2d is false\n", n);
n = -3;
while (n)
printf("%2d is true\n", n++);
printf("%2d is false\n", n);
return 0;
}
8 trouble.c
// trouble.c -- 这里误用了=导致了死循环
#include
int main(void)
{
long num;
long sum = 0L;
int status;
printf("Please enter an integer to be summed ");
printf("(q to quit): ");
status = scanf("%ld", &num);
while (status = 1)
{
sum = sum + num;
printf("Please enter next integer (q to quit): ");
status = scanf("%ld", &num);
}
printf("Those integers sum to %ld.\n", sum);
return 0;
}
9 boolean.c
// boolean.c -- 使用 _Bool类型的变量
#include
int main(void)
{
long num;
long sum = 0L;
_Bool input_is_good;
printf("Please enter an integer to be summed ");
printf("(q to quit): ");
input_is_good = (scanf("%ld", &num) == 1);
while (input_is_good)
{
sum = sum + num;
printf("Please enter next integer (q to quit): ");
input_is_good = (scanf("%ld", &num) == 1);
}
printf("Those integers sum to %ld.\n", sum);
return 0;
}
10 sweetie1.c
// sweetie1.c -- 一个计数循环
#include
int main(void)
{
const int NUMBER = 22;
int count = 1; // i初始化
while (count <= NUMBER) // 测试
{
printf("Be my Valentine!\n"); // 行为
count++; // 更新计数
}
return 0;
}
11 sweetie2.c
// sweetie2.c -- 使用for循环的计数循环
#include
int main(void)
{
const int NUMBER = 22;
int count;
for (count = 1; count <= NUMBER; count++)
printf("Be my Valentine!\n");
return 0;
}
12 for_cube.c
/* for_cube.c -- 使用for循环创建一个立方表 */
#include
int main(void)
{
int num;
printf(" n n cubed\n");
for (num = 1; num <= 6; num++)
printf("%5d %5d\n", num, num*num*num);
return 0;
}
13 postage.c
// postage.c --邮资
#include
int main(void)
{
const int FIRST_OZ = 46; // 2013 邮资
const int NEXT_OZ = 20; // 2013 邮资
int ounces, cost;
printf(" ounces cost\n");
for (ounces=1, cost=FIRST_OZ; ounces <= 16; ounces++,cost += NEXT_OZ)
printf("%5d $%4.2f\n", ounces, cost/100.0);
return 0;
}
14 zeno.c
/* zeno.c -- 求序列的和*/
#include
int main(void)
{
int t_ct; // 项计数
double time, power_of_2;
int limit;
printf("Enter the number of terms you want: ");
scanf("%d", &limit);
for (time=0, power_of_2=1, t_ct=1; t_ct <= limit;t_ct++, power_of_2 *= 2.0)
{
time += 1.0/power_of_2;
printf("time = %f when terms = %d.\n", time, t_ct);
}
return 0;
}
15 do_while.c
/* do_while.c -- 出口条件循环 */
#include
int main(void)
{
const int secret_code = 13;
int code_entered;
do
{
printf("To enter the triskaidekaphobia therapy club,\n");
printf("please enter the secret code number: ");
scanf("%d", &code_entered);
} while (code_entered != secret_code);
printf("Congratulations! You are cured!\n");
return 0;
}
16 entry.c
/* entry.c -- 出口条件循环 */
#include
int main(void)
{
const int secret_code = 13;
int code_entered;
printf("To enter the triskaidekaphobia therapy club,\n");
printf("please enter the secret code number: ");
scanf("%d", &code_entered);
while (code_entered != secret_code)
{
printf("To enter the triskaidekaphobia therapy club,\n");
printf("please enter the secret code number: ");
scanf("%d", &code_entered);
}
printf("Congratulations! You are cured!\n");
return 0;
}
17 rows1.c
/* rows1.c -- u使用嵌套循环 */
#include
#define ROWS 6
#define CHARS 10
int main(void)
{
int row;
char ch;
for (row = 0; row < ROWS; row++) /* line 10 */
{
for (ch = 'A'; ch < ('A' + CHARS); ch++) /* line 12 */
printf("%c", ch);
printf("\n");
}
return 0;
}
18 rows2.c
// rows2.c -- 依赖外部循环的嵌套循环
#include
int main(void)
{
const int ROWS = 6;
const int CHARS = 6;
int row;
char ch;
for (row = 0; row < ROWS; row++)
{
for (ch = ('A' + row); ch < ('A' + CHARS); ch++)
printf("%c", ch);
printf("\n");
}
return 0;
}
c语言troubc int类型占几个字节,程序设计基础(C)第06讲例程相关推荐
- c语言中布尔类型占几个字节,JAVA基本数据类型所占字节数是多少?
byte 1字节 short 2字节 int 4字节 long 8字节 char 2字节(C语言中是1字节)可以存储一个汉字 float 4字节 doub ...
- C语言布尔类型占几个字节,浅谈C语言中的布尔(bool)类型
我们知道在C++里有专门的bool类型,用来表示真或假.但是在C语言里没有这样的类型(至少我是一直这么认为的),表达式的值0为假,非0为真.所以条件判断语句( if(-).while(-) )非常灵活 ...
- C++ string类型占几个字节
在C语言中我们操作字符串肯定用到的是指针或者数组,这样相对来说对字符串的处理还是比较麻烦的,好在C++中提供了 string 类型的支持,让我们在处理字符串时方便了许多.这篇文章并不是讲解 ...
- C++中的string 类型占几个字节
C++中的string 类型占几个字节 一:先看一道面面试题: 题目是要求输出:TrendMicroSoftUSCN 然后要求修改程序,使程序能输出以上结果.代码如下: #include <io ...
- int 几个字节 java_Java中char,short,int,long占几个字节和多少位
1.字节:byte:用来计量存储容量的一种计量单位:位:bit 2.一个字节等于8位 1byte = 8bit char占用的是2个字节 16位,所以一个char类型的可以存储一个汉字. 整型: b ...
- java中double类型占几个字节_面试官:Java 中有几种基本数据类型是什么?各自占用多少字节?...
认识基本数据类型 在学习基本数据类型之前,我们先认识一下这两个单词:1.bit --位:位是计算机中存储数据的最小单位,指二进制数中的一个位数,其值为"0"或"1&quo ...
- int 几个字节 python_Python中一个int类型占了几个字节
Python中一个int类型占了几个字节 发布时间:2020-07-17 11:36:34 来源:亿速云 阅读:117 作者:清晨 小编给大家分享一下Python中一个int类型占了几个字节,希望大家 ...
- python int占用多少字节数_python中int类型占了多少个字节
python中int类型占了多少个字节 发布时间:2020-11-20 14:04:35 来源:亿速云 阅读:73 作者:小新 小编给大家分享一下python中int类型占了多少个字节,相信大部分人都 ...
- int为什么占4个字节?一个字节为什么是8位?
不知道大家有没有思考过这样的问题,一个字节为什么是8位呀,也许还有小伙伴不知道我说的这些是什么,没关系往下看. 第一个解释(历史)是IBM为System/360设计了一套8位EBCDIC编码,涵盖了数 ...
最新文章
- 几张图看懂列式存储(转)
- c语言储存10的500,c语言程序基础练习题500道
- matlab估计arma残差,写给你的金融时间序列分析:补完篇
- iOS日常工作之常用宏定义大全
- uvalive4744(数论)
- 源码注释性容器的创建及初始化
- FTP服务器配置固定IP才能访问
- 安装 mysql 数据库, 并做 主 从(二)
- .NET IO 复习中的误区
- mysql书单推荐_MySQL零基础入门推荐书籍?
- 10种流行的Java框架
- PowerDesign license安装问题
- leapftp怎么下载文件,用leapftp怎么下载文件
- [导入]2008大型历史正剧《朱元璋》更新第46集[完结]
- 如何在手机上查银行卡号?进来手把手教你!
- PTA:运算符重载(最简分数,c++)
- 解决“无法启动此程序,因为计算机中丢失VCRUNTIME140.dll,尝试重新安装此程序以解决此问题”方案合集
- MarkDown Pad2的Windows秘钥
- android 5.0 wifi移植,android wifi移植
- 解决 E45: 'readonly' option is set (add ! to override)
热门文章
- linux集群中mpi的并行计算环境简单配置,linux集群中MPI的并行计算环境简单配置(转)...
- Markdown示例
- 《Go语言实战》摘录:7.2 并发模式 - pool
- javaScript = == ===的区别
- NHibernate官方文档中文版——批量插入(Batch inserts)
- springday04-go1
- Okio 1.9简单入门
- [转载] python中list与string的转换
- jQuery读取和设定KindEditor值的方法
- Eclipse下创建Spring MVC web程序--非maven版