c语言补充定义函数 c语言代码补全

C语言,如何在VC6.0上,添加自定义函数?#include
#include
void
add(float
x,float
y)
//函数定义
{
printf("%5.2f\n",x y);//计算a b
}
main()
{float
a=0.0,b=0.0;
double
s;
scanf("%f,%f",a,b);//输入a
b
add(a,b);//直接调用函数
s=sqrt(a);
printf("跟号a=%f\n",s);
s=sqrt(b);
printf("跟号b=%f\n",s);
}
问题补充:
你的想法很好,可以的话去学下C吧,能学到你所想的
你想调用函数的话,把这函数做成一个C文件,以后需要时就合并用吧
C语言 补充函数/* 请在此文件中完成以下两个函数实现,并调试程序,实现程序功能*/
/* int readFile( struct stuinfo stu[] );*/
/* void input_high( struct stuinfo stu[], float high[], int n )*/
【c语言补充定义函数 c语言代码补全】/**/
/* 其它函数内容请勿更改*/
#include stdio.h
#include stdlib.h
#include string.h
struct stuinfo{
int serial;//学生编号
char name[10]; //学生姓名
};
int readFile( struct stuinfo stu[] );
void input_high( struct stuinfo stu[], float high[], int n );
void write_data();
void main()
{
struct stuinfo stu[30];
float stuHigh[30];
int stuNum;
int topStu=0;
// write_data();
stuNum = readFile( stu );
input_high( stu, stuHigh, stuNum );
return ;
}
/* 从文件"StuInfo.dat"中读出各位学生记录,以及记录个数 */
/* 学生记录存放在数组 stu中,函数返回学生人数*/
int readFile( struct stuinfo stu[] )
{
FILE *fp;
struct stuinfo *p;
int i=0;
if( (fp = fopen("StuInfo.dat", "rb " )) == NULL)
{
printf("file canot read!\n");
exit(1);
}
p=(struct stuinfo *)malloc(sizeof(struct stuinfo));
while(fread( p, sizeof(struct stuinfo), 1, fp)!=0)
{
stu[i]=*p;
i;
p=(struct stuinfo *)malloc(sizeof(struct stuinfo));
}
fclose(fp);
return i;
}
/*输入每个学生的身高信息*/
/*显示每位同学基本信息后 , 输入该同学的身高*/
/*计算并显示所有同学的平均身高*/
void input_high( struct stuinfo stu[], float high[], int n )
{
int i;
float sum=0;
for(i=0;in;i)
{
printf("Student %d serial, name:%s\n",i 1,stu[i].name);
printf("Please input student's height:");
scanf("%f",high[i]);
sum =high[i];
}
printf("student's average height:%f",sum/n);
}
/* 从键盘上输入学生信息,保存到StuInfo.dat文件中*/
void write_data( )
{
FILE *fp;
struct stuinfo stu[30];
int i, stuNum=0;
printf("Please input student number(30): ");
scanf("%d",stuNum);
if( stuNum30 )
{
printf("data error");
exit(1);
}
for( i=0; istuNum; i)
{
printf("Please input Student %d serial, name:\n", i 1 );
scanf("%d", stu[i].serial);
scanf("%s",stu[i].name);
}
if( (fp = fopen("StuInfo.dat", "wb " )) == NULL)
{
printf("file canot write!\n");
exit(1);
}
fwrite( stu, sizeof(struct stuinfo), stuNum, fp);
fclose( fp );
return;
}
如何在C语言中定义一个函数?需要准备的材料分别有:电脑、C语言编译器 。
1、首先 , 打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp 。
2、在test.cpp文件中,输入C语言代码:int fun(){return 1;} 。
3、编译器运行test.cpp文件,此时成功调用fun()函数输出了内容 。
c语言补充定义函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语言代码补全、c语言补充定义函数的信息别忘了在本站进行查找喔 。

    推荐阅读