1、40条C语言编程C语言编程1、字符数组1和2赋值为到,字符数组c2赋值为a到z后,输入字符数组1、2/* Note:Your choice is C IDE */#include stdio.hvoid main() char c126,c226; int i; for(i=0;i26;i+) c1i=A+i; c2i=a+i; for(i=0;i26;i+) printf(%c,c1i); printf(n); for(i=0;i=0&stri=A&stri=a&stri=z)Lowercase+; else Other+; printf(数据字符数量:%2dt大写字符数量%2dt小写字符数
2、量:%2dn,Num,Capital,Lowercase); printf(空格字符数量:%2dt其它字符数量:%2dn,Space,Other); 3、十进制转二进制/* Note:Your choice is C IDE */#include stdio.hvoid main() int i; printf(请输入一个十进制的数:); scanf(%d,&i); printf(%x,i); 4、十进制转二进制/* Note:Your choice is C IDE */#include stdio.hvoid main() int i,j,n,m; int a16= 0 ;system(c
3、ls); printf(请输入0到32767的数字); scanf(%d,&n); for(m=0;m=0;m-) printf(%d,am); if(m%4=0) printf( ); 5、n进制转为十进制/* Note:Your choice is C IDE */#include stdio.hvoid main() long t1; int i,n,t,t3; char a100; printf(please input a number sting:n); gets (a); strupr(a); t3=strlen(a); t1=0; printf(please input n(2
4、0or80or16):n); scanf(%d,&n); for(i=0;i=n&ai=n) printf(data error); exit(0); if(ai=0&ai9) t=ai-A+10; t1=t1*n+t; printf(the decimal is&ldn,t1); 6、以ip地址形式输出#includeint bin_dec(int x,int n)if(n=0) return 1; return x*bin_dec(x,n-1);void main() int i; int ip4=0; char a33; printf(please input binary number
5、); scanf(%s,a); for(i=0;i8;i+) if(ai=1) ip0+=bin_dec(2,7-i); for(i=8;i16;i+) if(ai=1) ip2+=bin_dec(2,15-i); for(i=16;i24;i+) if(ai=1) ip2+=bin_dec(2,31-i); for(i=24;i32;i+) if(ai=1) ip3+=bin_dec(2,31-i); if(ai=0) break; printf(ip:n); printf(%d%d%d%dn,ip0,ip1,ip2,ip3); 7、3个数由小到大排列#includevoid main()
6、int a,b,c,t; system(cls); printf(please input a,b,c:n); scanf(%d%d%d,&a,&b,&c); if(ab) t=a; a=b; t=b; if(ac) t=a; a=c; c=t; if(bc) t=b; b=c; c=t; printf(the order of the number is:n); printf(%d%d%d,a,b,c); 8编程要求输入整数a和b,若的结果大于100,则是输出的值,否则输出a+b的结果#includevoid main() int a,b,x,y; printf(please input a
7、 and b:n); scanf(%d%d,&a,&b); x=a*a+b*b; if(x100) printf(a2+b2=); printf(%d,x); else printf(a+b=%d,a+b); 9、编程判断输入的数是5又是7的整倍数,如果是输出yes否则输出no#includevoid main() int x; printf(please input a number:n); scanf(%d,&x); if(x%5=0&x%7=0) printf(yes); else printf(no); 10、判断闰年#includevoid main() int year; prin
8、tf(please input the year:n); scanf(%d,&year); if(year%4=0&year%100!=0|year%400=0) printf(%d is a leap year,year); else printf(%d is not a leap year,year); 11、阶层问题在你面前有一条长长的阶梯,如果你每层跨2阶,那么最后还有1阶,;如果你每步跨3阶,那么还有2阶;如果你每步跨5阶,那么还有4阶;如果你每步跨7阶时,最后才刚好走完,一阶也没有,请问阶梯至少有多少层?(求所有三位阶梯数)#include stdio.hvoid main() i
9、nt i; for(i=100;i1000;i+) if(i%2=1&i%3=2&i%5=4&i%6=5&i%7=0) printf(the number of the stairs is %dn,i); 12、编程对输入的百分制分数给出相应的等级,分数大于90为80到89为 ,70到79为,60到69为,60分以下为#include stdio.hvoid main() int score; printf(nplease inter score(score=100):); scanf(%d,&score); if(score=100) score=90; score=score/10; sw
10、itch(score) case 9: printf(the grade is A); break; case 8: printf(the grade is B); break; case 7: printf(the grade is C); break; case 6: printf(the grade is D); break; default: printf(the grade is E); 13、整数加减法练习练习者自己选择是进行加法运算,之后输入进行多少以内的加法以内的加法或减法运算,具体数值会由计算机随机产生,输入答案,计算机会根据输入的数据判断结果是否正确#include std
11、io.h#include#includevoid main() int a,b,c,sign,max; char sign1; printf(please select sign (1or other,1:-,other:+)n); scanf(%d,&sign); printf(please selectt the max number (10000):n); scanf(%d,&max); srand(unsigned long)time(0); a=rand()%max; b=rand()%max; while(a3) printf(Wron!ptess any key to exit)
12、; getch(); exit(0); else puts(wrong,tru again); while(password1!=password&i=3); printf(OK!press any key to continue.); getch(); break; case 2: do clrscr(); if(password1!=password) printf(pleasre logging in,press any key to continue.); getch(); break; else printf(*n); printf( please seledt:n); printf
13、(* 1.$100 *n); printf(* 2.$200 *n); printf(* 3.$300 *n); printf(* 4.$Return *n); printf(*n); CMoney=getch(); while(CMoney!=1&CMoney!=2&CMoney!=3&CMoney!=4); switch(CMoney) case 1: clrscr(); a=a-100; printf(*n); printf(* your credit minney is $100,thank you! *n); printf(* the balance is $%d. *n,a); p
14、rintf(* press aby key to return. *n); printf(*n); getch(); break; case 2: clrscr(); a=a-200; printf(*n); printf(* your credit minney is $200,thank you! *n); printf(* the balance is $%d. *n,a); printf(* press aby key to return. *n); printf(*n); getch(); break; case 3: clrscr(); a=a-300; printf(*n); p
15、rintf(* your credit minney is $300,thank you! *n); printf(* the balance is $%d. *n,a); printf(* press aby key to return. *n); printf(*n); getch(); break; case 4: break; break; case 3: printf(*n); printf(* thank you for your using! *n); printf(* Goodbye! *n); printf(*n); getch(); break; break; 15、用*打
16、印三角形#include stdio.hvoid main() int i,j,k; for(i=1;i5;i+) for(j=1;j=5-i;j+) printf( ); for(k=1;k=2*i-1;k+) printf(*); printf(n); 16、绘制余弦曲线绘制余弦曲线用到了反余弦函数acos(),通过纵坐标的值来求出横坐标的值,确定了横坐标的值,其对称位置的横坐标的值也就会可以确定,即用62减去确定的横坐标值,这里的62是一个近似值2*3.14*10#include stdio.h#includevoid main() double y; int x,m; for(y=1;
17、y= -1;y-=0.1) m=acos(y)*10; for(x=1;xm;x) printf( ); printf(*); for(;x62-m;x+) printf( ); printf(*n); getch();17、打印乘法口诀表#include stdio.hvoid main() int i,j; for(i=1;i=9;i+) for(j=1;j=i;j+) printf(%d*%d=%dt,i,j,i*j); printf(n); 18、输出*#*#*#$#include stdio.hvoid main() int a,b; for(a=1;a=3;a+) printf(*
18、#); printf($); 19、1计算s=1+1/2+1/3+1/4+1/n编程:#include stdio.h#includevoid main() int n; double i=1,sum=0; printf(input n :n); scanf(%d,&n); while(i=n) sum=sum+1/i; i+; printf(n=%d,sum=%lfn,n,sum);20、一元钱况换方案#include stdio.hvoid main() int i,j,k; for(i=0;i=10;i+) for(j=0;j=5;j+) for(k=0;k=2;k+) if(i+j*2
19、+k*5=10) printf(yi jiao%d, liangjiao %d, wujiao%dn,i,j,k);21、63+4736+74编程#include stdio.hvoid main() int x,y,z,x1,y1,z1,i,k,n,j=0; while(1) printf(please input an integern); scanf(%d,&n); if(n=100) printf(data errorn); continue; else if(n%10=0) printf(data errorn); continue; else x=n/10; y=n%10; z=10*y+x; break; for(i=11;i100;i+) if(i%10=0) continue;/*结束本次循环*/ else x1=i/10; y1=i%10; z1=10*y1+x1; if(n+i=z+z1&n!=z1) printf(%d+%d=%d+%dn,n,i,z,z1); j+; else continue; if(j=0) pri