using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[]args)
{
int[]num=new int[10];
Console.WriteLine("请输入十个数:");
for(int i=0;i<10;i++)
{
string s=Console.ReadLine();
int x=int.Parse(s);
num<i>=x;
}
/*for(int n=0;n<10;n++)
{
Console.WriteLine(num[n]);
}*/
int max=num[0];
for(int n=1;n<10;n++)
{
if(max<num[n])
max=num[n];
}
Console.WriteLine("最大值是{0}",max);
int min=num[0];
for(int a=1;a<10;a++)
{
if(min>num[a])
min=num[a];
}
Console.WriteLine("最小值是{0}",min);
int all=0;
for(int h=0;h<10;h++)
{
all=all+num[h];
}
double average=all/10;
Console.WriteLine("平均值是{0}",average);
Console.ReadKey(false);
}
}
}
using三种用法:
1、指令类型using+namespace,相当于java中import,指定导入类型
2、using别名using+别名=具体详细的类型:用于区分不同命名空间下相同类型
using AClass=nameSpace1.EqualClass;
using BClass=nameSpace2.EqualClass;
namespace nameSpace1
{
class EqualClass
{
public string MyName()
{
return"My is nameSpace1";
}
}
}
namespace nameSpace2
{
class EqualClass
{
public string MyName()
{
return"My is nameSpace2";
}
}
}
namespace TestProgram
{
using nameSpace1;
using nameSpace2;
class Program
{
static void Main(string[]args)
{
//测试别名的用法
AClass a=new AClass();
Console.WriteLine(a.MyName());
BClass b=new BClass();
Console.WriteLine(b.MyName());
Console.ReadKey();
}
}
}
3、using语句,定义一个范围,在范围结束时处理对象。
using(OleDbConnection connection=new OleDbConnection(connectionString))
{
using(OleDbCommand cmd=new OleDbCommand(SQLString,connection))
{
try
{
connection.Open();
int rows=cmd.ExecuteNonQuery();
return rows;
}
catch(System.Data.OleDb.OleDbException E)
{
connection.Close();
throw new Exception(E.Message);
}
}
}
include
void main()
{
int a[10],t,i,min,max,avg;
int s=0;
for(i=0;i<=9;i++)
{
printf("请输入第%d个数字:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=9;i++)
{
s=s+a[i];
if(0==i)
{
min=a[i];
max=a[i];
}
else
{
if(a[i]{
t=min;
min=a[i];
a[i]=t;
}
if(a[i]>max)
{
t=max;
max=a[i];
a[i]=t;
}
}
}
avg=s/10;
printf("max=%d\n",max);
printf("min=%d\n",min);
printf("avg=%d\n",avg);
}
#include
void main(){
int i,j,temp,sum=0,num[10];
for(i=0;i<10;i++){
printf("请输入第%d个数:",(i+1));
scanf("%d",&num[i]);
sum+=num[i];
}
for(i=0;i<10;i++){
for(j=0;jif(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
printf("这10个数的最大值是:%d,最小值是%d,平均值是:%d",num[9],num[0],(sum/10.0));
}
}
#include
void Input_Max_Min_Arv(int *p,int *pl,int *ps,double *arv){
int i;
printf("Please enter the 10 Numbers...\n");
for(*pl=*ps=i=0;i<10;i++){
scanf("%d",p+i);
*arv+=p[i];
if(p[i]
*ps=i;
if(p[i]>p[*pl])
*pl=i;
}
}
int main(int argc,char *argv[]){
int m[10],ml,ms;
double ma;
Input_Max_Min_Arv(m,&ml,&ms,&ma);
printf("The MAX is m[%d]==%d\nThe MIN is m[%d]==%d\n",ml,m[ml],ms,m[ms]);
printf("The arv is %f",ma/10);
return 0;
}
#include
void main()
{
int a[10],i,s=0;
float arry;
for(i=0;i<10;i++)
cin>>a[i];
for(i=0;i<10;i++)
{
for(int j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
int t=a[j];
a[j]=a[i];
a[i]=t;
}
}
}
cout<<"最小数="< cout<<"最大数="< for(i=0;i<10;i++)
{
s=s+a[i];
}
arry=s/10;
cout<<"平均值="<