ex08-01.cpp
来自「在c环境下的对数据结构进行讲解,包含有例题及答案」· C++ 代码 · 共 29 行
CPP
29 行
//EX08-01.cpp
#include <iostream.h> //cout,cin
#include <conio.h> // getch()
void main()
{ float data[20],ave=0;
int *n=new int,count=0,i,j;
do
{ cout <<"n=";
cin >> *n;
if (*n>0)
data[count++]=*n;
ave +=*n;
}
while (*n>0);
for (i=0;i<count-1;i++)
for (j=0;j<count-i-1;j++)
if (data[j]<data[j+1])
{ float t=data[j];
data[j]=data[j+1];
data[j+1]=t;
}
for (i=0;i<count;i++)
cout << data[i]<<' ';
cout << "\nave="<<(ave/count);
getch();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?