做编程题的时候说要用dat文件上传,要下什么能打开dat文件啊,好麻烦,就不能一直用c++吗
做编程题的时候说要用dat文件上传,要下什么能打开dat文件啊,好麻烦,就不能一直用c++吗
回复 嘿嘿大人:谢谢,那麻烦你再帮我看看以下哪里错了
#include <stdio.h>
float fun ( float h )
{
if(1000*h%10>=5);
{
h=(100*h+1)/100;
}
else
{
h=100*h/100;
}
return h;
}
main( )
{ float a;void NONO ();
printf ("Enter a: "); scanf ( "%f", &a );
printf ( "The original data is : " );
printf ( "%f \n\n", a );
printf ( "The result : %f\n", fun ( a ) );
NONO( );
}
void NONO ()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,
输出数据,关闭文件。 */
int i ;
float a ;
FILE *rf, *wf ;
rf = fopen("in.dat","r") ;
wf = fopen("out.dat","w") ;
for(i = 0 ; i < 20 ; i++) {
fscanf(rf, "%f", &a) ;
fprintf(wf, "%f\n", fun(a)) ;
}
fclose(rf) ;
fclose(wf) ;
}
--------------------Configuration: prog1 - Win32 Debug--------------------
Compiling...
prog1.c
c:\users\administrator\desktop\prog1.c(4) : error C2296: '%' : illegal, left operand has type 'float '
c:\users\administrator\desktop\prog1.c(8) : error C2181: illegal else without matching if
执行 cl.exe 时出错.
回复 终相守 °:我这么说不知道你懂不懂,你知道余数是怎么产生的不?余数必须整数和整数相除,然后得到的一个整数余一个整数,而你这里的h是一个浮点类型也就是小数类型,我这么说你应该知道哪里错了吧
#include <stdio.h>
float fun ( float h )
{
if((10000*h/10-1000*h/10*10)>=5);
{
h=(100*h+1)/100;
}
else
{
h=100*h/100;
}
return h;
}
main( )
{ float a;void NONO ();
printf ("Enter a: "); scanf ( "%f", &a );
printf ( "The original data is : " );
printf ( "%f \n\n", a );
printf ( "The result : %f\n", fun ( a ) );
NONO( );
}
void NONO ()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,
输出数据,关闭文件。 */
int i ;
float a ;
FILE *rf, *wf ;
rf = fopen("in.dat","r") ;
wf = fopen("out.dat","w") ;
for(i = 0 ; i < 20 ; i++) {
fscanf(rf, "%f", &a) ;
fprintf(wf, "%f\n", fun(a)) ;
}
fclose(rf) ;
fclose(wf) ;
}
--------------------Configuration: prog1 - Win32 Debug--------------------
Compiling...
prog1.c
C:\Users\Administrator\Desktop\prog1.c(8) : error C2181: illegal else without matching if
执行 cl.exe 时出错.
prog1.obj - 1 error(s), 0 warning(s)