转自:
http://blog.csdn.net/sxhelijian/article/details/15026159
示例代码:
- #include <iostream>
- using namespace std;
- const double pi=3.1415926;
- int main( )
- {
- float r,a;
- cout<<"输入半径:"<<endl;
- cin>>r;
- a=pi*r*r;
- cout<<"输出面积:";
- cout<<a<<endl;
- return 0;
- }
- float volume(float h,float r)
- {
- return pi*r*r*h;
- }
实践代码:
- #include <iostream>
- using namespace std;
- const double pi=3.1415926;
- int main( )
- {
- int a;
- cout<<"请输入一个数:"<<endl;
- cin>>a;
- if(a = 2)
- cout<<"你2了。";
- else
- cout<<"你不2。";
- return 0;
- }
示例代码:
- #include <iostream>
- using namespace std;
- const double pi=3.1415926;
- float area(float r);
- int main( )
- {
- float r1,a1;
- cin>>r1;
- a1=area(r1);
- cout<<a1<<endl;
- return 0;
- }
- float area(float r)
- {
- float a;
- a = pi*r*r;
- return a;
- }
实践代码:
- #include <iostream>
- using namespace std;
- float max(float x, float y);
- int main ()
- {
- float a,b,c;
- cin>>a>>b;
- c=max(a, b) ;
- cout<<"The max is "<<c<<endl;
- return 0;
- }
- float max(float x, float y)
- {
- float z;
- z=(x<y)? x : y ;
- return z;
- }
示例代码:
- #include<iostream>
- #include<cmath>
- using namespace std;
- int max(int,int);
- int main( )
- {
- int m,a,b;
- a=100;
- b=200;
- m=max(a,b);
- cout<<"最大:"<<m<<endl;
- return 0;
- }
- int max(int x,int y)
- {
- int z;
- if(x>y)
- z=x;
- else
- z=y;
- return z;
- }
实践代码:
- #include <iostream>
- using namespace std;
- float max(float x, float y);
- int main ()
- {
- float a,b,c;
- cin>>a>>b;
- c=max(a, b) ;
- cout<<"The max is "<<c<<endl;
- return 0;
- }
- float max(float x, float y)
- {
- float z;
- z=(x<y)? x : y ;
- return z;
- }