Lab 1/17基本資料型態
字元型態char
可以用來儲存英文字母和ASCII碼
參考程式-1:
====================
#include
void main()
{
char ch='a';
printf("ch=%c\n",ch);
printf("ch=%d\n",ch);
}
====================
參考程式-2
====================
#include
{
char ch='2';
printf("The ASCII of %c is %d.\n",ch,ch);
}
課堂練習:

5 Comments:
OK啦
OKOK
#include < stdio.h >
void main ()
{
int a=228;
printf("The ASCII of %c is %d \n",a,a);
}
總算可以了^^
偷偷告訴大家~上面int改成char也能跑出sigma喔~
不過後面printf中的%d會有問題~因為char只能有一個字元~而且字元要用單引號''將字元框起來
#include stdio.h
int main()
{
int ch=228;
printf(" %c is %d.\n",ch,ch);
return 0;
}
#include stdio.h
void main(void)
{
int i = 228;
printf("The ASCII of %d is %c.\n",i,i);
}
Post a Comment
<< Home