2d1.cpp

来自「C++ interview materials. Very helpful fo」· C++ 代码 · 共 52 行

CPP
52
字号
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
P2.9		◆2.D.1◆
Checkup:	MrZhou
*/

#include <iostream.h>

void sortData();//Forward Declaration 
void display(); //Forward Declaration

/* The Array Named amounts Is Defined Globally */
float amounts[10] = {200.5F,323,0,100.7F,314,523,256,10.90F,553.90F,0};

int main()
{
	sortData(); //Call The sortdata() Function 
	display();  //Call The display() Function  
	return 0;
}

void sortData()
{
	int counter=0;
	/* Traverse The Array */
	while(counter < 9)
	{
		float temp;
	/* Compare The Value Of Current Element With The Next */
		if(amounts[counter] > amounts[counter + 1])
		{
			/* Swap The Values */
			temp = amounts[counter];
			amounts[counter] = amounts[counter + 1];
			amounts[counter + 1] = temp;
			counter = 0;
			continue;
		}
		counter++;
	}
	return;
}

void display()
{
	/* Display All The Array Elements */
	for(int counter = 0;counter < 10; ++counter)
	{
		cout << "Element " << counter << ":  " << amounts[counter]		     << endl;
	}
	return;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?