美容院业绩表格图片:一道C语言编程题
来源:百度文库 编辑:查人人中国名人网 时间:2024/05/05 04:22:21
void fun(int a[],int x,int n)
{
int i,j;
for(i=0;i<n;i++)
{
if(x>=a[i])
{
for(j=n;j>i;j--)
a[j]=a[j-1];
a[i]=x;
break;
}
}
if(i==n)
a[i]=x;
}
// zd_19.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
int total;
void fun(int a[],int x,int n)
{
int i,j;
for(i=0;i<n;i++)
{
if(a[i]>=x && a[i+1]<=x)
{
n++;
total++;
for(j=n;j>=i;j--)
{
a[j+2]=a[j+1];
}
a[i+1]=x;
break;
}
}
}
int main(int argc, char* argv[])
{
int temp;
int num[100]={99,87,67,57,56,49,37,26,18,6};
scanf("%d",&temp);
total=10;
fun(num,temp,total);
for(int i=0;i<total;i++)
printf("%d\t",num[i]);
return 0;
}
输出:
57
99 87 67 57 57 56 49 37 26 18
6 Press any key to continue