C语言程序设计
C语言程序设计(A)
(20111-2012-1)
实验报告7
教学班级:冶金092 学号:04 姓名:徐荣辉课程教师:井福荣实验辅导教师:井福荣
一、实验前的源程序:
#include
float vol(int r)
{
float tj;
tj=(4*3.14*r*r*r)/3;
return tj;
}
int main();
{ int i;
float sum=0.0;
for(i=10;i<99;i++)
if(i%3==0)
sum+=vol(i);
printf("sum=%f",sum);
return 0;
}
实验错误报告:
--------------------配置: mingw2.95 - CUI Release, 编译器类型: MinGW (Old)--------------------
检查文件依赖性...
正在编译 D:\C-Free\C-Free Standard\temp\未命名2.cpp...
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:9: parse error before `{'
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:11: parse error before `for'
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:11: parse error before `;'
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:11: syntax error before `++'
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:14: ANSI C++ forbids declaration `printf' with no type
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:14: `int printf' redeclared as different kind of symbol
[Error] D:\C-Free\C-FREE~1\mingw32\Include\stdio.h:204: previous declaration of `int printf(const char *, ...)'
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:14: initializer list being treated as compound expression
[Warning] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:14: warning: initialization to `int' from `float'
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:15: parse error before `return'
构建中止未命名2: 9 个错误, 1 个警告
修改后的源程序:
#include
float vol(int r)
{
float tj;
tj=(4*3.14*r*r*r)/3;
return tj;
}
int main()
{ int i;
float sum=0.0;
for(i=10;i<99;i++)
if(i%3==0)
sum+=vol(i);
printf("sum=%f",sum);
return 0;
}
实验前的源程序
#include
int main()
{
float ho=100,h=h0,s=0;
int i;
for( i=1;i<=10;i++)
{ s=s+h;
h=h/2.0;
}
printf("the total h is %f(m)\n",s);
printf("the total h is %f(m)",h);
return 0;
}
实验错误报告
--------------------配置: mingw2.95 - CUI Release, 编译器类型: MinGW (Old)--------------------
检查文件依赖性...
正在编译D:\C-Free\C-Free Standard\temp\未命名2.cpp...
[Error] D:\C-Free\C-Free Standard\temp\未命名2.cpp:4: `h0' undeclared (first use this function)
[Error] D:\C-Free\C-Free Standard\temp\未命名 2.cpp:4: (Each undeclared
identifier is reported only once
[Error] D:\C-Free\C-Free Standard\temp\未命名2.cpp:4: for each function it appears in.)
构建中止未命名2: 3 个错误, 0 个警告
修改后的源程序
#include
int main()
{
float h0=100,h=h0,s=0;
int i;
for( i=1;i<=10;i++)
{ s=s+h;
h=h/2.0;
}
printf("the total h is %f(m)\n",s);
printf("the total h is %f(m)",h);
return 0;
}