C语言题.写一函数,用冒泡法对输入的一组数按由小到大顺序排序(要求形参为数组),main函数调用实现

C语言题.写一函数,用冒泡法对输入的一组数按由小到大顺序排序(要求形参为数组),main函数调用实现排序.要C的,不要C++.

#include<stdio.h>
void sort(int a[],int n)
{
int i,j, t;
for(j=0;j<n-1;j++)
{
for(i=0;i<n-j-1;i++)
{
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
}
void main()
{
int i;
int s[8];
for(i=0;i<8;i++){
scanf("%d",&s[i]);
}
sort(s,8);
printf("The sort is:\n");
for(i=0;i<8;i++)
printf("%d\n",s[i]);
}

追问

另求一个,"十进制整数转换对应的二进制"的函数,在main主函数中输入一个十进制的整数,输出对应的二进制数.也是求C语言,完了再加5悬赏
不是c++的

追答#include<stdio.h>
int dectobin(int n,char buffer[])
{
int i=0;
for(;n>0;n>>=1,i++)
{
buffer[i] = '0'+n%2;
}
return i;
}
void main()
{
int num;
char buffer[256];
scanf("%d",&num);
num=dectobin(num,buffer);
for(num--;num>=0; num--)
printf("%c",buffer[num]);
printf("\n");
}

追问

再求: 用递归法写一个求幂的函数,并在主函数实现调用c语言.马上加分,我要换一下程序
再求: 用递归法写一个求幂的函数,并在主函数实现调用.继续c语言.马上加分,我要换一下程序

追答

不好意思,递归法我不再行,刚刚给你找了个普通的。
#include
int main()
{
int n, m, i;
int res = 1;
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++)
{
res *= n;
}
printf("%d\n", res);
return 0;
}

追问

算了,我再另外求一下,谢了

温馨提示:答案为网友推荐,仅供参考