摘要: 代码实现: 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 阅读(2240) 评论(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 阅读(10821) 评论(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 阅读(37179) 评论(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 阅读(2698) 评论(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 阅读(47889) 评论(0) 推荐(0) 编辑