c语言编程:任意输入16个数且按从大到小顺序排列排成4*4方阵

c语言编程:任意输入16个数且按从大到小顺序排列排成4*4方阵,第1张

这是快速排序做的,main函数中的quicksort是排序,如果不喜欢快速排序你可首芦以把这个函数重新写。

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,e

scanf("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

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12395736.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存