2009年3月24日 星期二

C語言的範例 –改變背景顏色 - 回文數判斷

C語言的範例 改變背景顏色
題目:Press any key to change color, do you want to try it. Please hurry up! 
1.程式分析:             
2.程式源代碼: 
#include  
void main(void) 
{ 
int color; 
for (color = 0; color < 8; color++) 
  
 textbackground(color);/*設置文本的背景顏色*/ 
 cprintf("This is color %d\r\n", color); 
 cprintf("Press any key to continue\r\n"); 
 getch();/*輸入字元看不見*/ 
 } 
} 

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

C語言的範例 回文數判斷
題目:一個5位數,判斷它是不是回文數。即12321是回文數,個位與萬位相同,十位與千位相同。    
1.程式分析:
2.程式源代碼: 
main( ) 
{ 
long ge,shi,qian,wan,x; 
scanf("%ld",&x); 
wan=x/10000; 
qian=x%10000/1000; 
shi=x%100/10; 
ge=x%10; 
if (ge==wan&&shi==qian)/*個位等於萬位並且十位等於千位*/ 
 printf("this number is a huiwen\n"); 
else 
 printf("this number is not a huiwen\n"); 
}