1、 乘法口诀表 #include #include void main(void) int i,j,x,y; clrscr(); printf(“nn * * * 乘法口诀表 * * * nn“); x=9; y=5; for(i=1;i void main() char SelectKey,CreditMoney,DebitMoney; while(1) do clrscr(); puts(“=“); puts(“| Please select key: |“); puts(“| 1. Quary |“); puts(“| 2. Credit |“); puts(“| 3. Debit |“)
2、; puts(“| 4. Return |“); puts(“=“); SelectKey = getch(); while( SelectKey!=1 switch(SelectKey) case 1: clrscr(); puts(“=“); puts(“| Your balance is $1000. |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 2: do clrscr(); puts(“=“); puts(“| Please select Credit money: |“); pu
3、ts(“| 1. $50 |“); puts(“| 2. $100 |“); puts(“| 3. Return |“); puts(“=“); CreditMoney = getch(); while( CreditMoney!=1 switch(CreditMoney) case 1: clrscr(); puts(“=“); puts(“| Your Credit money is $50,Thank you! |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 2: clrscr(); p
4、uts(“=“); puts(“| Your Credit money is $100,Thank you! |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 3: break; break; case 3: do clrscr(); puts(“=“); puts(“| Please select Debit money: |“); puts(“| 1. $50 |“); puts(“| 2. $100 |“); puts(“| 3. $500 |“); puts(“| 4. $1000 |“
5、); puts(“| 5. Return |“); puts(“=“); DebitMoney = getch(); while( DebitMoney!=1 switch(DebitMoney) case 1: clrscr(); puts(“=“); puts(“| Your Debit money is $50,Thank you! |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 2: clrscr(); puts(“=“); puts(“| Your Debit money is $1
6、00,Thank you! |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 3: clrscr(); puts(“=“); puts(“| Your Debit money is $500,Thank you! |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 4: clrscr(); puts(“=“); puts(“| Your Debit money is $1000,Thank you!
7、 |“); puts(“| Press any key to return. |“); puts(“=“); getch(); break; case 5: break; break; case 4: clrscr(); puts(“=“); puts(“| Thank you for your using! |“); puts(“| Good bye! |“); puts(“=“); return; 模拟 ATM(自动柜员机)界面 #include void main() int Password=0,Number=0,price=58,i=0; while( Password != 123
8、4 ) if( i = 3 ) return; i+; puts(“Please input Password: “); scanf(“%d“, i=0; while( Number!=price ) do puts(“Please input a number between 1 and 100: “); scanf(“%d“, printf(“Your input number is %dn“,Number); while( !(Number=1 else if( Number = 70 getch(); 用二维数组实现矩阵转置 /* 用二维数组实现矩阵的转置 */ #include #d
9、efine ROW 3 #define COL 4 main() int matrixAROWCOL,matrixBCOLROW; int i,j; clrscr(); printf(“Enter elements of the matrixA,“); printf(“%d*%d:n“,ROW,COL); for( i=0; imax)/* 保存至 row 行的最小数 */ min=max; printf(“The minimum of maximum number is %dn“,min); for(max=a00,row=0;rowarowcol) min=arowcol; if(maxm
10、in)/*保存至 row 行的最大数 */ max=min; printf(“The maximum of minimum numbers is %dn“,max); printf(“nPress any key to quit.n“); getch(); 利用数组求前 n 个质数 #define N 50 main() int primesN; int pc,m,k; clrscr(); printf(“n The first %d prime numbers are:n“,N); primes0=2;/*2 是第 一个质数 */ pc =1;/*已有第一个质数 */ m =3;/*被测试的
11、数从 3 开始 */ while(pcN) /*调整 m 使它为下一个质数 */ k=0; while(primesk*primesk=m) if(m%primesk=0) /*m 是合数 */ m+=2;/*让 m 取下一个奇数 */ k=1;/*不必用 primes0=2 去测试 m,所以 k 从一开始 */ else k+;/*继续用下一个质数去测试 */ primespc+=m; m+=2;/*除 2 外,其余质数均是奇数 */ /*输出 primes0至 primespc-1*/ for(k=0;kpc;k+) printf(“%4d“,primesk); printf(“nn Pr
12、ess any key to quit.n “); getch(); 编制万年历 #include “stdio.h“ long int f(int year,int month) /*f(年,月 )年 1,如月 3;否则, f(年,月 )年 */ if(month3) return year-1; else return year; long int g(int month) /*g(月 )月 13,如月 3;否则, g(月 )月 1*/ if(month3) return month+13; else return month+1; long int n(int year,int mont
13、h,int day) /*N=1461*f(年、月 )/4+153*g(月 )/5+日 */ return 1461L*f(year,month)/4+153L*g(month)/5+day; int w(int year,int month,int day) /*w=(N-621049)%7(0=w7)*/ return(int)(n(year,month,day)%7-621049L%7+7)%7); int date1267; int day_tbl 12=31,28,31,30,31,30,31,31,30,31,30,31, 31,29,31,30,31,30,31,31,30,31
14、,30,31; main() int sw,leap,i,j,k,wd,day; int year;/*年 */ char title=“SUN MON TUE WED THU FRI SAT“; clrscr(); printf(“Please input the year whose calendar you want to know: “);/*输 入年 */ scanf(“%d%*c“,/*输入年份值和掠过值后的回车 */ sw=w(year,1,1); leap=year%4=0/*判闰年 */ for(i=0;i12;i+) for(j=0;j6;j+) for(k=0;k7;k+
15、) dateijk=0;/*日期表置 0*/ for(i=0;i12;i+)/*一年十二个月 */ for(wd=0,day=1;day=day_tblleapi;day+) /*将第 i 1 月的日期填入日期表 */ dateiwdsw=day; sw=+sw%7;/*每星期七天,以 0至 6计数 */ if(sw=0) wd+;/*日期表每七天一行,星期天开始新的一行 */ printf(“n|=The Calendar of Year %d =|n|“,year); for(i=0;i6;i+) /*先测算第 i+1 月和第 i+7 月的最大星期数 */ for(wd=0,k=0;k7;
16、k+)/*日期表的第六行有日期,则 wd!=0*/ wd+=datei5k+datei+65k; wd=wd?6:5; printf(“%2d %s %2d %s |n|“,i+1,title,i+7,title); for(j=0;jwd;j+) printf(“ “);/*输出四个空白符 */ /*左栏为第 i+1 月,右栏为第 i+7 月 */ for(k=0;k7;k+) if(dateijk) printf(“%4d“,dateijk); else printf(“ “); printf(“ “);/*输出十个空白符 */ for(k=0;k7;k+) if(datei+6jk) printf(“%4d“,datei+6jk); else printf(“ “); printf(“ |n|“); /*scanf(“%*c“);/*键入回车输出下一个月的日历 */ puts (“=|“) ; puts(“n Press any key to quit.“);