5位跳水高手将参加10m高台跳水决赛,好事者让5人据实力预测比赛结果。

  • A选手说:B第二,我第三;
  • B选手说:我第二,E第四;
  • C选手说:我第一,D第二;
  • D选手说:C最后,我第三;
  • E选手说:我第四,A第一。

决赛成绩公布后,每位选手的预测都说对了一半,即一对一错。

请用逻辑表达式对比赛结果进行表达

大家知道,计算机是采用二进制表示数的。但是,字符呢?一种解决办法就是编码,比如,ASCII码。

所以,字符,'a',这是英文小写字母a在程序语言里的表示方式,的ASCII编码是01100001,或者用十进制表示为97。

这里,字符的本质当然就是字符本身,'a',而表象则是:01100001(97)。

当你想要看(输出)一个字符的本质时,就用%c,而想看字符的表象(即编码)时,则用%d。

所以,在程序中:

char ch;

ch = 'a';

printf("%c", ch);

将输出字符: a。而

printf("%d", ch);

将输出字符a的编码:97

The use of the equals sign = as an assignment operator has been frequently criticized, due to the conflict with equals as comparison for equality. This results both in confusion by novices in writing code, and confusion even by experienced programmers in reading code.

Selection Statements

Three types of selection statements exist in C:

if ( expression ) statement

In this type of if-statement, the sub-statement will only be executed iff the expression is non-zero.

if ( expression ) statement else statement

In this type of if-statement, the first sub-statement will only be executed iff the expression is non-zero; otherwise, the second sub-statement will be executed. Each else matches up with the closest unmatched if, so that the following two snippets of code are not equal:

if(expression)
   if(secondexpression)statement1;
else
   statement2;

if(expression)
   {
     if(secondexpression)statement1;
   }
else
   statement2;

because in the first, the else statement matches up with the if statement that has secondexpression for a control, but in the second, the braces force the else to match up with the if that has expression for a control.

 

If ...... else if ..... else if ..... else

 

 

 

程序最后一行:

return 0;

有什么用?

Style Guide

There’s no one, right way to stylize code. But there are definitely a lot of wrong (or, at least, bad ways). Even so, CS50 does ask that you adhere to the conventions below so that we can reliably analyze your code’s style. Similarly do companies typically adopt their own, company-wide conventions for style.