c++程序。请求解答

来源:百度知道 编辑:UC知道 时间:2024/05/25 19:58:32
对下面程序进行改正并输出结果

修改下列程序,并调试出结果,说明程序功能(即程序的作用)
#include <stdio.h>
#define pi=3.1416
const float r=3.2
main()
{
float s1,s2,c1,c2,r1;
c1=pi*r*r;
s=2*pi*r;
r=2.8;
c2=pi*r*r;
s2=2*pi*r;
cont<c2<s2;
}

#include <iostream> //头文件
using namespace std;

#define pi 3.1416 //没有=号

const double r=3.2 ;//加分号

void main() //返回类型
{
double s1,s2,c1,c2,r1;
c1 = pi*r*r;
s1 = 2*pi*r;
r1 = 2.8; //r1
c2 = pi*r*r;
s2 = 2*pi*r;
cout << c2 << " " << s2 << endl; //输出是<<
}

求圆的周长和面积
#include <iostream.h> //头文件
#define pi 3.1416 //没有=
const float r=3.2 ;//加分号
void main() //返回类型
{
float s1,s2,c1,c2,r1;
c1 = pi*r*r;
s1 = 2*pi*r;
r1 = 2.8; //r1
c2 = pi*r*r1; //r1
s2 = 2*pi*r1; //r1
cout << c2 << " " << s2 << endl; //输出是<<
}

程序功能是求圆的周长和面积
先指出你的错误:1、const float r=3.2 ,你把r定义成了const了,后面你又定义r=2.8,这就错了。r定义成了const就不能对它更改了。改成static
2、cont<c2<s2:错了。c语言的输出语句为printf.其他一些警告都是float和double类型的转换,没太大的影响,可以想不管。还有一个就是main函数没有定义类型,也是