Tuesday, January 17, 2006

Lab 1/17基本資料型態

字元型態char
可以用來儲存英文字母和ASCII碼

參考程式-1:
====================
#include "stdio.h"//""用<>代換
void main()
{
char ch='a';
printf("ch=%c\n",ch);
printf("ch=%d\n",ch);
}
====================


參考程式-2
====================
#include
"stdio.h"//""用<>代換
void main(void)
{
char ch='2';
printf("The ASCII of %c is %d.\n",ch,ch);
}

====================

課堂練習:

5 Comments:

At Tue Jan 17, 08:45:00 PM, Anonymous Anonymous said...

OK啦

 
At Tue Jan 17, 08:45:00 PM, Anonymous Anonymous said...

OKOK

 
At Tue Jan 17, 08:53:00 PM, Anonymous Anonymous said...

#include < stdio.h >
void main ()
{
int a=228;
printf("The ASCII of %c is %d \n",a,a);
}

總算可以了^^
偷偷告訴大家~上面int改成char也能跑出sigma喔~
不過後面printf中的%d會有問題~因為char只能有一個字元~而且字元要用單引號''將字元框起來

 
At Tue Jan 17, 08:58:00 PM, Anonymous Anonymous said...

#include stdio.h
int main()
{
int ch=228;
printf(" %c is %d.\n",ch,ch);
return 0;
}

 
At Tue Jan 17, 08:58:00 PM, Anonymous Anonymous said...

#include stdio.h
void main(void)
{

int i = 228;
printf("The ASCII of %d is %c.\n",i,i);
}

 

Post a Comment

<< Home