1 / 15

Continuous Addition Exercise in C Programming

Learn C programming with a practice exercise on continuous addition of integers between two positive numbers. See examples and assignment operators.

Download Presentation

Continuous Addition Exercise in C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Speaker: Wen-Ching Lo 10/7計程實習課

  2. 第一次作業繳交方式 • 請將作業上傳到hw1資料夾中 • 遲交一天扣10分(三天以後就0分) • 繳交方式: • 作業完成後,將你的程式改名為 學號.c (ex:987030XX.c) • 使用以下指令修改權限:chmod 604 學號.c • 再執行 cp 學號.c /home1/student/phd98/d9806/cp/hw1

  3. if • if ( grade >= 60 ) printf( "Passed\n" );

  4. if…else… • if ( grade >= 60 ) printf( "Passed\n"); else printf( "Failed\n");

  5. if ( grade >= 60 ) printf( "Passed.\n" ); else { printf( "Failed.\n" ); printf( "You must take this course again.\n" ); }

  6. if…else if…else • if ( x < -1 ) y = 1; else if ( x < 0 ) y = 2; else if ( x < 1 ) y = 3; else y = 4;

  7. && 和 || • && 且 Ex: if ( A && B ) { …//A和B同時都要成立 } • || 或 Ex: if ( A || B ) { …//A和B兩者只要成立一個 }

  8. while • int product = 2; //初始值 while ( product <= 1000 ) product = 2 * product;

  9. Examples of other assignment operators: c += 3 ( c = c + 3) d -= 4 (d = d - 4) e *= 5 (e = e * 5) f /= 3 (f = f / 3) g %= 9 (g = g % 9) • Increment operator (++) • Can be used instead of c+=1 • Decrement operator (--) • Can be used instead of c-=1

  10. c=5 printf( “%d”, ++c );//先做加1的動作,再印出C • Prints 6 printf( "%d", c++ ); //先做印出C的動作,再加1 • Prints 5 • In either case, c now has the value of 6 • Preincrementing and postincrementing have the same effect ++c; printf( “%d”, c ); • Has the same effect as c++; printf( “%d”, c );

  11. 習題 • 連續加法運算 輸入兩個正數(起始值與結束值且起始值小於結束值才可運算)做這兩個數之間整數的連續加法

  12. 請輸入連續加法的起始值:1 請輸入連續加法的結束值:10 the sum is 55 請輸入連續加法的起始值:1 請輸入連續加法的結束值:100 the sum is 5050 請輸入連續加法的起始值:50 請輸入連續加法的結束值:1 Bye Bye!

More Related