C++语言 输入n个整数求平均值

如题所述

第1个回答  2020-02-14
VC++
6.0的程序如下,如果在.NET下运行,头文件需要改动,并加上域名的说明语句;
#include<iostream.h>
void
main()
{
int
n,i,num,total;
n=num=total=0;
float
ave;
cout<<"enter
the
number
of
numbernal:
"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"enter
the
numbernal:
"<<endl;
cin>>num;
total=total+num;
}
ave=total/n;
cout<<"the
average
of
numbernal
is:
"<<ave<<endl;
}
第2个回答  2019-05-05
vc++
6.0的程序如下,如果在.net下运行,头文件需要改动,并加上域名的说明语句;
#include<iostream.h>
void
main()
{
int
n,i,num,total;
n=num=total=0;
float
ave;
cout<<"enter
the
number
of
numbernal:
"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"enter
the
numbernal:
"<<endl;
cin>>num;
total=total+num;
}
ave=total/n;
cout<<"the
average
of
numbernal
is:
"<<ave<<endl;
}