PS:已经测设过。没者芦带问题,给分吧
#include <stdio.h>哗培
int ptTag(int a[],int low,int high)
{
int Tagkey = a[low]
while (low <high)
{
while (low <high &&a[high] >= Tagkey)
high = high -1
a[low] = a[high]
while (low <high &&a[low] <= Tagkey)
low=low+1
a[high] = a[low]
}
a[low] = Tagkey
return low
}
void qsort(int a[], int low, int high)
{
int pt
if(low <high)
{
pt = ptTag(a, low ,high)
qsort(a,low,pt-1)
qsort(a,pt+1,high)
}
}
void quicksort(int a[], int n)
{
qsort(a,0,n-1)
}
void main()
{
int i
int a[16]
printf("input 16 num:")
for(i=0i<16i++)
scanf("%d",&a[i])
printf("\n")
quicksort(a,16)
printf("the sorted numbers :\n")
for(i=0i <16i++)
{
if(i%4 == 0 ) printf("\n")
printf("%12d",a[i])
}
printf("\n")
}
long a,b,c,d,escanf("x%,x%,x%,x%",&a,&b,&c,&d)
e |= d <饥贺悔<烂正 24 | c <<16 | b <拍中<8 | a
printf("x%\n",e)
#include <stdio.h>#include <stdlib.h>
#include <limits.h>
int cmp(const void *a,const void *b)/*排序*/
{
return 枣郑*(const int *)a-*(const int *)b
}
void bit_prt(const int a)/*二进制输出*/
{
int i
unsigned int mask=1<<(CHAR_BIT*sizeof(a)-1)
for (i = 1 mask i++)
{
putchar(a&mask?'1':'0')
mask>>=1
if (i%4==0)putchar(' ')
}
}
int main(int argc, char* argv[])
{
int a[4]
int i
for (i = 0 i<4 i++) {
scanf("%x",&a[i])
}
qsort(a,4,sizeof(int),cmp)
for (i = 0 行烂i 档岩漏< 4 i++) {
printf("0x%X\t\t%d\t\t",a[i],a[i])
bit_prt(a[i])
putchar('\n')
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)