摘要: 代码实现: 1 #include<iostream> 2 using namespace std; 3 void reverse() 4 { 5 char s; 6 if((s=getchar())!='\n') 7 reverse(); 8 if(s!='\n') 9 cout<<s;10 }11 void main()12 { 13 reverse();14 }运行图示: 阅读全文
posted @ 2012-04-19 21:15 iamvirus 阅读(2239) 评论(0) 推荐(0) 编辑
摘要: 代码实现:#include<iostream>using namespace std;long fun(char *s){ int i,t; long sum=0; for(i=0;s[i];i++) { if(s[i]<='9') t=s[i]-'0'; else t=s[i]-'a'+10; sum=sum*16+t; } return sum;}main(){ long m; char s[50]; cout<<"请输入十六进制数: "; cin>>s; m=fun(s);... 阅读全文
posted @ 2012-04-19 20:41 iamvirus 阅读(10819) 评论(0) 推荐(0) 编辑
摘要: 代码: 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 void fun(int a) 5 { 6 int k,i; 7 k=sqrt(a); 8 for(i=2;i<=k;i++) 9 if(a%i==0) break;10 if(i>k) 11 cout<<a<<"是素数"<<endl;12 else 13 cout<<a<<"不是素数"<<endl;14 }15 阅读全文
posted @ 2012-04-19 20:25 iamvirus 阅读(37177) 评论(1) 推荐(0) 编辑
摘要: 用三个函数分别求当b^2-4ac大于0、等于0和小于0时的根。并输出结果。从主函数输入a、b、c的值。 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 void fun(int a,int b,int c) 5 { 6 if(b*b-4*a*c>=0) 7 cout<<"第一个实根是 "<<(-b+sqrt(b*b-4*a*c))/(2*a)<<" 第二个实根是 "<<(-b-sqrt(b*b-4* 阅读全文
posted @ 2012-04-19 16:25 iamvirus 阅读(2695) 评论(1) 推荐(0) 编辑
摘要: 代码实现: 1 #include<iostream> 2 using namespace std; 3 int max(int x,int y) 4 { 5 int temp; 6 if(x<y) 7 { 8 temp=x;x=y;y=temp; 9 }10 while(y!=0)11 {12 temp=x%y;13 x=y;14 y=temp;15 }16 return(x);17 }18 int min(int x,int y)19 {20 int max... 阅读全文
posted @ 2012-04-19 11:49 iamvirus 阅读(47884) 评论(0) 推荐(0) 编辑
摘要: 算法: 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 float ave,score,max,min,sum=0; 6 int n=0; cin>>score; 7 max=min=score; 8 while(score>=0) 9 {10 sum=sum+score;11 n++;12 cin>>score;13 ave=sum/n;14 if(score<0) break;15 ... 阅读全文
posted @ 2012-04-13 11:44 iamvirus 阅读(13420) 评论(0) 推荐(0) 编辑
摘要: 算法: 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int main() 5 { 6 int i,k,n; 7 for(n=3;n<=100;n++) 8 { 9 k=sqrt(n);10 for(i=2;i<=k;i++)11 if(n%i==0) break;12 if(i>=k+1)13 cout<<n<<"是素数"<<endl;14 }15 ... 阅读全文
posted @ 2012-04-13 10:59 iamvirus 阅读(450) 评论(1) 推荐(0) 编辑
摘要: 用do while 的解法: 1 #include<iostream> 2 using namespace std; 3 void main() 4 { 5 int i=1,j; 6 do 7 { j=1; 8 while(j<=i) 9 {10 cout<<i<<'x'<<j<<'='<<i*j<<' ';11 j++;12 }13 cout<<endl;14 i++;15 }16 while(i<=9);17 }用fo... 阅读全文
posted @ 2012-04-12 23:09 iamvirus 阅读(352) 评论(0) 推荐(0) 编辑
摘要: 本题算法来源于网络,罪过罪过!代码实现: 1 #include<iostream> 2 using namespace std; 3 void main() 4 { 5 int z,a,b,i,j,f1,f2,min; 6 f1=133/19; 7 f2=133/23; 8 min=133; 9 for(i=0;i<f1;i++)10 { 11 for(j=0;j<f2;j++)12 {13 z=133-19*i-23*j;14 if(z>=0&&min>z)15 {16 min=z;a=i;b=j;17 }18 }19 }20 cout&l 阅读全文
posted @ 2012-04-08 15:03 iamvirus 阅读(2078) 评论(0) 推荐(0) 编辑
摘要: 2/1,3/2,5/3,8/5,13/8,21/13,......代码实现: 1 #include<iostream> 3 using namespace std; 4 void main() 5 { 6 int f1=0,f2=1;float t,s=0; 7 for(int i=1;i<=13;i++) 8 { 9 f1=f1+f2;10 f2=f1+f2;11 t=(float)f2/f1;12 s+=t;13 }14 cout<<s<<endl;15 }预览图: 阅读全文
posted @ 2012-04-08 14:32 iamvirus 阅读(241) 评论(0) 推荐(0) 编辑