基于visual Studio2013解决面试题之1401冒泡排序

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               



题目



解决代码及点评

  1.   
  1.   
  1. <code class="language-cpp">/* 
  2.     冒泡排序 
  3. */  
  4. #include <iostream>  
  5. using namespace std;  
  6.   
  7. int main()  
  8. {  
  9.     int a[10];  
  10.     for(int i=0;i<10;i++)  
  11.         a[i]=rand()%100;  
  12.     for(int i=0;i<10;i++)  
  13.         for(int j=0;j<10-i;j++)  
  14.         {  
  15.             if(a[j]<a[j+1])  
  16.             {  
  17.                 int temp=a[j];  
  18.                 a[j]=a[j+1];  
  19.                 a[j+1]=temp;  
  20.             }  
  21.         }  
  22.         for(int i=0;i<10;i++)  
  23.             cout<<a[i]<<" ";  
  24.         system("pause");  
  25.   
  26.         return 0;  
  27. }  
  28.   
  29.   
  30. </code>  
/* 冒泡排序*/#include <iostream>using namespace std;int main()int a[10]; for(int i=0;i<10;i++)  a[i]=rand()%100for(int i=0;i<10;i++)  for(int j=0;j<10-i;j++)  {   if(a[j]<a[j+1])   {    int temp=a[j];    a[j]=a[j+1];    a[j+1]=temp;   }  }  for(int i=0;i<10;i++)   cout<<a[i]<<" ";  system("pause");  return 0;}


代码下载及其运行

代码下载地址:http://download.csdn.net/detail/yincheng01/6704519

解压密码:c.itcast.cn


下载代码并解压后,用VC2013打开interview.sln,并设置对应的启动项目后,点击运行即可,具体步骤如下:

1)设置启动项目:右键点击解决方案,在弹出菜单中选择“设置启动项目”


2)在下拉框中选择相应项目,项目名和博客编号一致

3)点击“本地Windows调试器”运行


程序运行结果








           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/fdgugfv/article/details/83989401