The C programming language Test

Test 1-1  运行“hello world ”程序

#include <stdio.h>

int main()
{
printf("Hello world!\n");
}

去掉字符串,int不会报错,,,去掉其余的标点,函数名会报错。

Test 1-2  

#include <stdio.h>

int main()
{
printf("Hello world!\n\c");
}

output:

Hello world !

c

Test 1-3

#include <stdio.h>

int main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;

printf("The Transformation\n");

while(fahr <= upper)
{celsius = (5.0 / 9.0) * (fahr - 32.0);
printf("%3.0f %6.1f\n",fahr, celsius);
fahr = fahr + step;
}
}

output加入了“the transformation”的标题。

Test 1-4

#include <stdio.h>

int main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
celsius = lower;

printf("The Transformation\n");

while(celsius <= upper)
{ fahr = celsius / (5.0 / 9.0) + 32.0;       //celsius = (5.0 / 9.0) * (fahr - 32.0);//
printf("%3.0f %6.1f\n",celsius, fahr);
celsius = celsius + step;
}
}

output 摄氏温度转换为华氏温度的转换表!

Test 1-5

#include <stdio.h>

int main()
{
float fahr;

printf("The Transformation\n");

for(fahr = 300; fahr >= 0; fahr = fahr - 20)
printf("%3.0f %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32.0));

}

温度转换表倒序output!

Test1-6

#include <stdio.h>

int main()
{
int c;

while(c = getchar() != EOF)
printf("%d\n", c);

}

验证getchar() != EOF 是0 还是 1  我用while 当表达式为真.output的结果为1,为假 则不执行output函数,即为0,实践证明为1.

此题与答案有点出入..不太理解答案的写法!

答案:

#include<stdio.h>

main()

{

int c;

while (c = getchar != EOF);

printf("%d\n",c);

printf("%d - at EOF\n",c);

}

Test 1-7

此题思路错误,错误理解成需要在原有程序里打印EOF的值,即是否=EOF的真假值

属于想多了型

答案是如此简单....

#include<stdio.h>

main()

{

printf(" EOF is %d\n",EOF);

}

Test 1-8

#include <stdio.h>

int main()
{
double c,n;
n = 0;

while((c = getchar()) != EOF)
if(c == ' '&& c == '\n'&& c == '\t')
++n;
printf("%.0f\n",n);

}

思路  当检测到输入内容里有 空格 \n \t时 统计+1; 思路被证实错误;

答案如下:

#include <stdio.h>
// count blanks, tabs, and newlines //

int main()
{
int c, nb, nt, nl;

nb = 0;
nt = 0;
nl = 0;

while ((c = getchar()) != EOF)
{
if(c == ' ')
++nb;
if(c == '\t')
++nt;
if(c == '\n')
++nl;
}
printf("%d %d %d\n",nb, nt, nl);

}

 我说为什么这些程序都没有效果..跳出循环..原来是需要ctrl+z 中止 在回车输出统计结果!! 汗...

Test 1-9 & Test 1-10  不会

原文地址:https://www.cnblogs.com/jango/p/3376565.html