2.1 CDAA 2.x>20&&x oid main( nt n=I, x,y while(l) xsqrt(100+n); y=sqrt( 168+n); if(x*x=(100+n)&&y*y=(168+n) n++ }2v int nnl n2n3 n4.n5 printf("please input n: ") scanf("%d", &n) printf("n=%d\n",n) nl=n/10000; n2=n%10000/1000; 3=n%1000/100 n4=n%100/10 ns=n%10; if(n1=0) printf("n is 5 wei shu! \n") else if(n21=0) printf("n is 4 wei shu! \n"); else if(n31=0)printf("n is 3 wei shu! \n"); else if(n4=0)printf("n is 2 wei shu! \n") else if(n5!=0)printf("n is I wei shu! n") if(n5!=O)printf("%", n5) if(n4=O)printf("%d", n4) if(n3!=O)printf("%d", n3);
2.1 CDAA 2.2 1.5 3 4 2.x>20&&x=0 x #include void main() { int n=1,x,y; while(1) { x=sqrt(100+n); y=sqrt(168+n); if(x*x==(100+n) && y*y==(168+n)) break; n++; } printf("%d",n); } 2. void main() { int n,n1,n2,n3,n4,n5; printf("please input n:"); scanf("%d",&n); printf("n=%d\n",n); n1=n/10000; n2=n%10000/1000; n3=n%1000/100; n4=n%100/10; n5=n%10; if(n1!=0) printf("n is 5 wei shu!\n"); else if(n2!=0) printf("n is 4 wei shu!\n"); else if(n3!=0) printf("n is 3 wei shu!\n"); else if(n4!=0) printf("n is 2 wei shu!\n"); else if(n5!=0) printf("n is 1 wei shu!\n"); if(n5!=0)printf("%d",n5); if(n4!=0)printf("%d",n4); if(n3!=0)printf("%d",n3);
if(n2!=O)printf("%d", n2) if(n1=O)printf("%d", n1) void maino int i, n, a, t, sum=0 printf("please input n and a: ) scanf("%d%d",&n, &a) for(i=l; i <=n; i++) sum=sum+a a=a*10+t printf("Sn=%d", sum) 4.略(学完“数组”后再做此题) oid maino float sn=100.0.hn=sn/2 for(n=2;n<=l0,n++) snsn+2*hn hn=hn/2 printf("the total of road is %f\n", sn); printf("the tenth is %f meter \n", hn) }67 int n.t. number=20 float a=2. b=1.s=0 for(n=l; n<=number; n++) sSta/b t=a;a=a+b,b=t/*这部分是程序的关键,请猜猜t的作用* printf("sum is %9.6f\n", s);
if(n2!=0)printf("%d",n2); if(n1!=0)printf("%d",n1); } 3. void main() { int i,n,a,t,sum=0; printf("please input n and a:"); scanf("%d%d",&n,&a); t=a; for(i=1;i<=n;i++) { sum=sum+a; a=a*10+t; } printf("Sn=%d",sum); } 4.略(学完“数组”后再做此题) 5. void main() { float sn=100.0,hn=sn/2; int n; for(n=2;n<=10;n++) { sn=sn+2*hn; hn=hn/2; } printf("the total of road is %f\n",sn); printf("the tenth is %f meter\n",hn); } 6.略 7. void main() { int n,t,number=20; float a=2,b=1,s=0; for(n=1;n<=number;n++) { s=s+a/b; t=a;a=a+b;b=t;/*这部分是程序的关键,请猜猜 t 的作用*/ } printf("sum is %9.6f\n",s); }
8 #include oid main( int cap=0, alp=0, spa=0, num=0, other=0 printf("please input some letters: " while((ch=getchar)!=n) if(ch>=o'&&ch=A&&ch=a'&&ch=z)alp++; se if(ch==') se otner printf("Capital letter=%d, Lowercase letter=%d, Number=%d, Space=%d, Others=%d\n", cap, alp, num, spa, other)
8. #include void main() { char ch; int cap=0,alp=0,spa=0,num=0,other=0; printf("please input some letters:"); while((ch=getchar())!='\n') { if(ch>='0'&&ch='A'&&ch='a'&&ch<='z') alp++; else if(ch==' ') spa++; else other++; } printf("Capital letter=%d,Lowercase letter=%d,Number=%d,Space=%d, Others=%d\n",cap,alp,num,spa,other); }