第一题:#includeintCheck(inta,intb,intc){intnum[9]={0};inti,j;inttemp=0;intn=a*1000000+b*1000+c;for(i=0;i<9;i++){num[9-1-i]=n%10;if(num[9-1-i]==0)return0;n/=10;}...
第一题:
#include
int Check(int a,int b,int c)
{
int num[9] = {0};
int i,j;
inttemp = 0;
int n = a*1000000+b*1000+c;
for(i=0;i<9;i++)
{
num[9-1-i] = n%10;
if(num[9-1-i]==0)
return 0;
n /= 10;
}
for(i=0;i<8;i++)
for( j=i+1;j<9;j++)
if(num[i]==num[j])
return 0;
return 1;
}
int main()
{
int a,b,c;
for(a=123;a<=987;a++)
for(b=123;b<=987;b++)
{
c = a+b;
if(c<=987&&a
printf("%d + %d =%d\n",a,b,c);
}
return 0;
}
第二题
#include
void mergesort(int *a,intleft,int right);
void merge(int *a,intleft,int middle,int right);
int main()
{
int a[10]= {34,42,1,75,56,27,18,84,91,63};
int i;
printf("排序前:\n");
for (i=0; i<10; i++)
{
printf("%3d",a[i]);
}
printf("\n");
mergesort(a,0,9);
printf("排序后:\n");
for (i=0; i<10; i++)
{
printf("%3d",a[i]);
}
printf("\n");
return 0;
}
void mergesort(int *a,intleft,int right)
{
int middle;
if(left
{
middle=(left+right)/2;
mergesort(a,left,middle);
mergesort(a,middle+1,right);
merge(a,left,middle,right);
}
}
void merge(int *a,intleft,int middle,int right)
{
int n1=middle-left+1;
int n2=right-middle;
int *L=new int[n1+1];
int *R=new int[n2+1];
int i,j=0,k;
for (i=0; i
{
*(L+i)=*(a+left+i);
}
*(L+n1)=100;
for (i=0; i
{
*(R+i)=*(a+middle+i+1);
}
*(R+n2)=100;
i=0;
for (k=left; k<=right; k++)
{
if(L[i]<=R[j])
{
a[k]=L[i];
i++;
}
else
{
a[k]=R[j];
j++;
}
}
delete [] L;
delete [] R;
}
第三题
#include
void quiksort(int a[],intlow,int high)
{
int i = low;
int j = high;
int temp = a[i];
if( low < high)
{
while(i < j)
{
while((a[j] >= temp) &&(i < j))
{
j--;
}
a[i] = a[j];
while((a[i] <= temp) &&(i < j))
{
i++;
}
a[j]= a[i];
}
a[i] = temp;
quiksort(a,low,i-1);
quiksort(a,j+1,high);
}
else
{
return;
}
}
void main()
{
int arry[5] = {67,24,18,3,55},int i;
quiksort(arry,0,4);
for(i=0;i<5;i++)
{
printf("%d ",arry[i]);
}
printf("\n");
}
展开