{
  "question_id": 7435119,
  "question_title": "指针排序问题",
  "question_content": "<p>输入10个数&#xff0c;按绝对值从大到小排序输出。\n输入形式&#xff1a;输入10个float实数\n输出形式&#xff1a;保留小数点后两位有效数字；输出从大到小排列\n</p>",
  "difficulty": "困难",
  "answer_id": 53405662,
  "answer_content": "<pre>\n<code class=\"hljs language-cpp\">#include &lt;math.h&gt;\n#include &lt;stdio.h&gt;\nvoid paixu(float *p,int n)\n{\n\tint i,j;\n\tfor (i &#61; 0; i&lt;n-1; i&#43;&#43;) \n\t{ //控制n-1趟冒泡\n\t\tfor (j &#61; 0; j&lt;n - 1 - i; j&#43;&#43;)\n\t\t{\n\t\t\tif (fabs(p[j])&lt;fabs(p[j &#43; 1])) \n\t\t\t{ //比较相邻的两个元素\n\t\t\t\tfloat tmp; //临时变量\n\t\t\t\ttmp &#61; p[j]; //交换\n\t\t\t\tp[j] &#61; p[j &#43; 1];\n\t\t\t\tp[j &#43; 1] &#61; tmp;\n\t\t\t}\n\t\t}\n\t}\n}\n\nint main()\n{\n\tfloat f[10];\n\tint i;\n\tfor(i&#61;0;i&lt;10;i&#43;&#43;)\n\t\tscanf(&#34;%f&#34;,&amp;f[i]);\n\tpaixu(f,10);\n\tfor(i&#61;0;i&lt;10;i&#43;&#43;)\n\t\tprintf(&#34;%.2f &#34;,f[i]);\n\n\treturn 0;\n}</code></pre>\n\n<p> </p>\n",
  "tag_name": "c语言",
  "cpp": "#include <math.h>\n#include <stdio.h>\nvoid paixu(float *p,int n)\n{\n\tint i,j;\n\tfor (i = 0; i<n-1; i++) \n\t{ \n\t\tfor (j = 0; j<n - 1 - i; j++)\n\t\t{\n\t\t\tif (fabs(p[j])<fabs(p[j + 1])) \n\t\t\t{ \n\t\t\t\tfloat tmp; \n\t\t\t\ttmp = p[j]; \n\t\t\t\tp[j] = p[j + 1];\n\t\t\t\tp[j + 1] = tmp;\n\t\t\t}\n\t\t}\n\t}\n}\nint main()\n{\n\tfloat f[10];\n\tint i;\n\tfor(i=0;i<10;i++)\n\t\tscanf(\"%f\",&f[i]);\n\tpaixu(f,10);\n\tfor(i=0;i<10;i++)\n\t\tprintf(\"%.2f \",f[i]);\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470144",
  "status": 1,
  "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/14.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "weixin_45811118"
}