这个程序哪有问题?

[复制链接]
查看11 | 回复0 | 2008-3-8 22:05:46 | 显示全部楼层 |阅读模式
//VS2005#include using namespace std; void printAarry(int num[],int counter) { counter=sizeof(num)/sizeof(num[0]); //这么取数组长度,未必正确,至少ANSI C不行吧.//若不用STL,并不能定义大小不确定的数组,//所以,通常情况下数组长度是已知的,这里counter可传入一个常数.for(int i=0;i<counter;i++) { cout<<num<<","; } cout<<endl; } void butte(int num[],int counter) { counter=sizeof(num)/sizeof(num[0]); int temp; for(int i=0;i<counter;i++) { for(int j=0;j<counter-i-1;j++) { if(num[j+1]<num[j]) { temp=num[j]; num[j]=num[j+1]; num[j+1]=temp; } } } } void main() { int s[] = {5,7,4,3,11,8,12,32,1},counter=0; cout<<"输入排序前的数组:"<<endl;//若不定义一个变量,也可传入一个常量给counter.//比如printAarry(s,9);printAarry(s,counter); butte(s,counter); cout<<"排序后的数组:"<<endl; printAarry(s,counter); }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行