`
bcyy
  • 浏览: 1822467 次
文章分类
社区版块
存档分类
最新评论

算法竞赛入门经典 1.2 变量及输入

 
阅读更多
//程序1-4 A+B问题(C语言)
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",a+b);
	return 0;
}

//C++语言
#include<iostream>
using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a+b<<endl;
	return 0;
}

//程序1-5 圆柱体的表面积(c语言)
#include<stdio.h>
#include<math.h>

int main()
{
	const double pi=4.0*atan(1.0);
	double r,h,s1,s2,s;
	scanf("%lf%lf",&r,&h);
	s1=pi*r*r;
	s2=2*pi*r*h;
	s=s1*2.0+s2;
	printf("Area=%.3lf\n",s);
	return 0;
}

//C++语言
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	const double pi=4.0*atan(1.0);		//定义常量
	double r,h,s1,s2,s;
	cin>>r>>h;				//输入
	s1=pi*r*r;				//底面积
	s2=2*pi*r*h;				//侧面积
	s=s1*2+s2;				//表面积
	cout<<"Area="<<s<<endl;			//输出
	return 0;
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics