程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
/*判断错误函数*/
void puterror(int i){
int a;
for(a=1;a<=i;a++)
printf(" ");
printf("^\n");
}
/*求最大函数*/
int maxx(int a,int n[]){
int i,b;
b=0;
for(i=1;i<=a;i++)
if(n[b]<n[i])
b=i;
return n[b];
}
/*求最小函数*/
int minn(int a,int n[]){
int i,b;
b=0;
for(i=1;i<=a;i++)
if(n[b]>n[i])
b=i;
return n[b];
}
/*求总和函数*/
long sum(int a,int n[]){
int i;
long s=0;
for(i=0;i<=a;i++)
s+=n[i];
return s;
}
/*求平均数函数*/
float ave(int a,long s){
return (float)s/(a+1);
}
/*求方差函数*/
float var(int a,int n[],float ave){
float s=0;
int i;
for(i=0;i<=a;i++)
s+=pow(n[i]-ave,2);
return s/(a+1);
}
/*标准值*/
float sta(int var){
return sqrt(var);
}
/*主函数*/
int main(){
char num[100],i,a;
int n[50]={0};
gets(num);
i=0;
a=0;
while(num[i]!='\0'){
if(isdigit(num[i]))
n[a]=n[a]*10+(num[i]-48);
else if(isspace(num[i]))
a++;
else{
puterror(i);
printf("Error : This is not number.\n");
break;
}
i++;
}
printf("\n");
if(a==0) /*判断如果是一个就说只有一数字,不然就说有多少个数字*/
printf("Here only one number.\n");
else
printf("There are %d numbers.\n",a+1);
printf("The Max number is %d.\n",maxx(a,n));
printf("The Min number is %d.\n",minn(a,n));
printf("The Sume is %d.\n",sum(a,n));
printf("The average is %.2f.\n",ave(a,sum(a,n)));
printf("The Variance is %.2f.\n",var(a,n,ave(a,sum(a,n))));
printf("The Standard Deviation is %.2f.\n",sta(var(a,n,ave(a,sum(a,n)))));
getch();
}
程序就是这个了..
你是拿来做作业用???
跟我差不多..
如果对程序还有什么问题的话,回复就是的.