מבוא לשפת C תרגול 4: ביטויים לוגיים ומשפטי תנאי מבוסס על השקפים שחוברו ע"י שי ארצי, גיתית רוקשטיין, איתן אביאור וסאהר אסמיר עבור הקורס "מבוא למדעי המחשב"

  • Published on
    21-Dec-2015

  • View
    220

  • Download
    3

Embed Size (px)

Transcript

<ul><li> Slide 1 </li> <li> C 4: " , , " " " , " . </li> <li> Slide 2 </li> <li> 4 . 2 if </li> <li> Slide 3 </li> <li> 4 . 3 : * -Turbo C . ! , int 4 . / "* sizeof %d %c1 char %d2 int %ld4 long int %f4 float %lf8 double </li> <li> Slide 4 </li> <li> 4 . 4 char: ? : char ( ) -128 -127. -256 ASCII. char %c, . char %c, scanf , ASCII . (+, -, *,/,%, / %d ') char ! </li> <li> Slide 5 </li> <li> 4 . 5 char , : char ch = 'B'; ch "", ASCII B. ch %c B : printf("Numeric value is %d, character is %c", ch, ch); : Numeric value is 66, character is B ! </li> <li> Slide 6 </li> <li> 4 . 6 C " ". , . : % - , ( !). ++ - ( , ) -- - (") : +=, -=, ' x+=y; ;x=x+y, ' </li> <li> Slide 7 </li> <li> 4 . 7 : - . cast type-cast. " . : (type)expression </li> <li> Slide 8 </li> <li> 4 . 8 - ? int a = 1,b = 2; double result = (double) a / b; 1. cast , a -int -double. 2. , . b - int -double. 3. : 1.0/2.0=0.5. 4. double double. . </li> <li> Slide 9 </li> <li> 4 . 9 -BUG : #include int main(void) { char c="Y"; int price = 1999999; double half_price = (double)(price/2); printf("UPPER CASE: %c, lower case: %c\n", c, c-A+a); printf("Half price of 1,999,999 is %.2lf\n", half_price); return 0; } ? ? </li> <li> Slide 10 </li> <li> Slide 11 54, '', ''." - , : (, " x -100") (, " x&gt;54") (, " x&gt;54 homework&gt;60")"&gt; </li><li> 4 . 11 ? , . , " x&gt;54, '', ''." - , : (, " x -100") (, " x&gt;54") (, " x&gt;54 homework&gt;60") </li> <li> Slide 12 54 true x -54, false . true, "". . C : 0 false. -0 (, 1) true."&gt; </li><li> 4 . 12 . true false ("" ""). , x&gt;54 true x -54, false . true, "". . C : 0 false. -0 (, 1) true. </li> <li> Slide 13 </li> <li> 4 . 13 : , 1 (, true). , 0 (, false). , ? int x = 79; int passing = (x &gt; 54); printf(Passing status: %d\n, passing); , . "" . </li> <li> Slide 14 </li> <li> 4 . 14 ... (, x -54). , . , : x + 5 &gt; 3 * y 35 &gt; 42 x &lt; x + 1 ... ? ! </li> <li> Slide 15 = y ( , x y) --: x 0 temp54, '', ''." C if. " ". </li><li> Slide 26 </li> <li> 4 . 26 if if : if (expression) statement; expression ... , if. , statement. , statement if. : if (x &lt; 55) printf(You have failed!); -1 0. -if ! </li> <li> Slide 27 </li> <li> 4 . 27 double temp; int is_liquid; printf(Enter temprature: ); scanf(%lf, &amp;temp); is_liquid = (0 &lt; temp) &amp;&amp; (temp &lt; 100); if (is_liquid) printf(In liquid state.); if (temp &lt; 0) printf(Frozen.); if (temp &gt; 100) printf(Boiled.); </li> <li> Slide 28 </li> <li> 4 . 28 int grade; printf(Enter test grade: ); scanf(%d, &amp;grade); if (grade &lt; 55) printf(Failed.); if (grade &gt;= 55) printf(Passed.); ( grade 55) : , , . (... ...) . </li> <li> Slide 29 </li> <li> 4 . 29 ... ... , C . : if (expression) statement 1 ; else statement 2 ; expression , statement 1. , statement 2. ( ) ! </li> <li> Slide 30 </li> <li> 4 . 30 ... int grade; printf(Enter test grade: ); scanf(%d, &amp;grade); if (grade &lt; 55) printf(Failed.); else printf(Passed.); , . ! </li> <li> Slide 31 </li> <li> 4 . 31 if , ifelse , . , : if (grade &lt; 55) printf(Failed.); else printf(Passed.); -statement (indentation). : , ; . </li> <li> Slide 32 </li> <li> 4 . 32 , " ", . , -, . . , : , ! ... </li> <li> Slide 33 </li> <li> 4 . 33 , . , ? int grade = 25; printf(The grade is %d\n, grade); if (grade &gt; 54) printf(Passed.\n); printf(Very good!\n); !? </li> <li> Slide 34 54) printf(Passed.\n); printf(Very good!\n); -printf -if!"&gt; </li><li> 4 . 34 ... , " ". , : int grade = 25; printf(The grade is %d\n, grade); if (grade &gt; 54) printf(Passed.\n); printf(Very good!\n); -printf -if! </li> <li> Slide 35 54) { printf(Passed.\n); printf(Very good!\n); }"&gt; </li><li> 4 . 35 , if? : . , "" statements , -if. : int grade = 25; printf(The grade is %d\n, grade); if (grade &gt; 54) { printf(Passed.\n); printf(Very good!\n); } </li> <li> Slide 36 </li> <li> 4 . 36 -else... if (grade &gt; 54) { printf(Passed.\n); printf(Very good!\n); } else { printf(Failed.\n); printf(What a pity!\n); } "". </li> <li> Slide 37 </li> <li> 4 . 37 ... . , . : if (grade &lt; 55) { printf(Failed.); } else { printf(Passed.); } </li> <li> Slide 38 </li> <li> 4 . 38 : if (grade &lt; 55) { printf(Failed.); } else { printf(Passed.); } , . ! </li> <li> Slide 39 </li> <li> 4 . 39 grade=40? if (grade &lt; 55) if (grade &gt; 52) grade = 55; /* factor */ else printf(Passed without factor.); else -if ! Passed without factor. . . ! -C </li> <li> Slide 40 = 53) grade = 55; } else printf(Passed without factor.); Passed without factor. grade&gt;=55."&gt; </li><li> 4 . 40 -else -if ? " : if (grade &lt; 55) { if (grade &gt;= 53) grade = 55; } else printf(Passed without factor.); Passed without factor. grade&gt;=55. </li> <li> Slide 41 10000) { if (airspeed &lt; 100) { printf(Warning! Crash danger!); } !"&gt; </li><li> 4 . 41 . 10,000 , -100 ", . ? if (altitude &gt; 10000) { if (airspeed &lt; 100) { printf(Warning! Crash danger!); } ! </li> <li> Slide 42 </li> <li> 4 . 42 , visibility . - ( ). , . ? ? if (visibility == 0) { turn_on_red_light(); } </li> </ul>

Recommended

View more >