C语言 [英] c programming language
本文介绍了C语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的程序,请对其进行更正.它出现非函数错误调用.
here is my program please correct it .it comes error call of non function.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<dos.h>
#include<io.h>
void main()
{
FILE *fp;
int n;
float med,j;
clrscr();
cout<<"HOW MANY NOS.? ";
cin>>n;
cout<<"ENTER SOME RANDOM NOS.";
fp = fopen("random.txt", "w+");
/* write some data to the file */
for(int i=1;i<=n;i++)
{
cin>>j;
fprintf(fp,"%f\n",j);
}
/* close the file */
fclose(fp);
fp=fopen("random.txt", "r+");
//fseek(fp, 0, SEEK_SET);
i=0;
float mean=0;
float arr[20];
while(i<n)
{
fscanf(fp,"\n%f",&arr[i]);
mean=mean+arr[i];
i++;
}
cout<<"store";
for(i=0;i<n;i++)
{Bin= (NumBins * (X - Xmin)) / (Xmax - Xmin);
if (Bin < 0) Bin= 0; else if (Bin >= NumBins) Bin= NumBins - 1;
cout<<"\nbin is :"<<ele(arr[i]/n);
}
//***************************MEDIAN*****************************
int temp;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[j]<arr[i])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
int div;
cout<<"mean is : "<<mean/n;
if(n%2!=0)
{
med=(n+1)/2;
cout<<"\nmedian is :"<<arr[med-1];
}
else
{
div=n/2;
med=(arr[div]+arr[div-1])/2;
cout<<"\nmedian is :"<<med;
}
//********************Eucledian Distance***********************************
float eucl[20];
fseek(fp, 0, SEEK_SET);
for(int p=0;p<n;p++)
fscanf(fp,"\n%f",&eucl[p]);
cout<<"\n";
for(int f=0;f<n;f++)
for(int k=0;k<n;k++)
{
temp=eucl[f]-eucl[k];
cout<<"\nEucledian Distance of "<<eucl[f]<<" with respect to "<<eucl[k]<<" is "<<temp;
}
fclose(fp);
getch();
}
推荐答案
帮自己一个忙,对我们有利:缩进您的代码.
如果看起来像这样,则更容易阅读,了解和调试:
Do yourself and us a favour: indent your code.
It is a lot easier to read, understasnd and debug if it looks like this:
float eucl[20];
fseek(fp, 0, SEEK_SET);
for(int p=0;p<n;p++)
fscanf(fp,"\n%f",&eucl[p]);
cout<<"\n";
for(int f=0;f<n;f++)
for(int k=0;k<n;k++)
{
temp=eucl[f]-eucl[k];
cout<<"\nEucledian Distance of "<<eucl[f]<<" with respect to "<<eucl[k]<<" is "<<temp;
}
fclose(fp);
getch();
我也强烈建议所有变量都使用有意义的名称,并以逗号开头,并在开始时始终使用"{"和}". IE.即使您在for循环中只有一行代码,也请使用方括号:这样一来,如果您需要添加另一行,则很明显它在循环中或不在循环中.
使用改善问题"小部件来编辑您的问题.
I would also strongly recommend meaningful names for all variables, an increas in commens, and the use of ''{'' and ''}'' at all times when you are beginning. I.e. even if you have a single line of code in a for loop, use brackets: That way if you need to add another, it is obvious that it is or isn''t in the loop.
Use the "Improve question" widget to edit your question.
这篇关于C语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文