[程設習題] C Primer Plus Ch3 #2

2.  請寫出一個程式,他能讓你打入ASCII(例如66),然後他能印出ASCII碼對應出的字元。


 


程式碼如下






#include “stdafx.h”


#include <stdio.h>                                                       //引入stdio.h


#include <stdlib.h>                                                      //引入stdlib.h


 


int main(int argc, char* argv[])


{


     char txt1;                                                          //宣告一個變數txt1,型態是字元


     printf(“Please Enter the ASCII code of the character:\n”);          //印出字串


     scanf(“%d”, &txt1);                                                 //程式等待使用者打入字元的ASCII


     printf(“The ASCII code is %d and the character is %c”,txt1,txt1);   //印出字元ASCII碼代表的字元


     printf(“\n\n”);                                                     //印出字串


     system(“PAUSE”);                                                    //「按任意鍵繼續」的程式,讓程式暫停


     return 0;                                                           //函數結束,傳回整數並跳回原本呼叫的地方


}