目:给一个不多于5位的正整数,要求:一、求它是 几位数,二、逆序打印出列位数字. 1,程序解析:学会分化出每一名数,似下讲明:(这个地方是 一种简单的算法,师专数002班*鑫供应) 2,程序源代码: main( ) { long a,b,c,d,e,x; scanf(“%ld”,&x); a=x10000;分化出万位 b=x%100001000;分化出千位 c=x%1000100;分化出百位 d=x%10010;分化出十位 e=x%10;分化出个位 if (a!=0) printf(“there are 5,%ld %ld %ld %ld %ld\n”,e,d,c,b,a); else if (b!=0) printf(“there are 4,%ld %ld %ld %ld\n”,e,d,c,b); else if (c!=0) printf(" there are 3,%ld %ld %ld\n",e,d,c); else if (d!=0) printf(“there are 2,%ld %ld\n”,e,d); else if (e!=0) printf(" there are 1,%ld\n",e); }
【程序30】 题目:一个5位数,判断它是 不是 回文数.即12321是 回文数,个位与万位同样,十位与千位同样. 1,程序解析:同29例 2,程序源代码: main( ) { long ge,shi,qian,wan,x; scanf(“%ld”,&x); wan=x10000; qian=x%100001000; shi=x%10010; ge=x%10; if (gewan&&shiqian)个位等于万位同时且十位等于千位 printf(“this number is a huiwen\n”); else printf(“this number is not a huiwen\n”); } 【程序31】 题目:请输入星期几的第一个字母来判断一下是 星期几,介入第一个字母同样,那么接着 判断第二个字母. 1,程序解析:用状况语句对比好,介入第一个字母同样,那么判断用状况语句或if语句判断第二个字母. 2,程序源代码: #include void main() { char letter; printf(“please input the first letter of someday\n”); while ((letter=gainch())!=‘Y’)当所按字母为Y时才终了 { switch (letter) {case ‘S’:printf(“please input second letter\n”); if((letter=gainch())‘a’) printf(“saturday\n”); else if ((letter=gainch())‘u’) printf(“sunday\n”); else printf(“data error\n”); break; case ‘F’:printf(“friday\n”);break; case ‘M’:printf(“monday\n”);break; case ‘T’:printf(“please input second letter\n”); if((letter=gainch())‘u’) printf(“tuesday\n”); else if ((letter=gainch())‘h’) printf(“thursday\n”); else printf(“data error\n”); break; case ‘W’:printf(“wednesday\n”);break; default:printf(“data error\n”); } } }
【程序32】 题目:Press any key to change color,do you desire to try it.Please hurry up! 1,程序解析: 2,程序源代码: #include <conio.h> 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”); gainch();输入字符看不见 } }