C语言 这个小程序 哪里错了呢?
#include<stdio.h>#definen5voidside_rank(int*a);intmain(void){intside[n]={0};charloop=...
#include<stdio.h>
#define n 5
void side_rank(int *a);
int main(void)
{
int side[n] = { 0 };
char loop = '\0';
do
{
printf("Please enter %d num: ", n);
for (int i = 0; i < n; i++)
scanf("%d", side[i]);
side_rank(*side);
printf("Do you want to run again?(Y,YES N,NO");
scanf("%c", loop);
}
while (loop == 'Y' || loop == 'y');
}
void side_rank(int *a)
{
int i, j, k, s, z;
for (i = n - 1; i >0; i = k)
{
for (j = 0,k=0; j < i; j++)
{
if (*(a + j) > *(a + j + 1))
{
s = *(a + j);
*(a + j) = *(a + j + 1);
*(a + j + 1) = s;
k = j;
}
}
}
for (z = 0; z < n; z++)
{
printf("%5d", *(a + i));
}
} 展开
#define n 5
void side_rank(int *a);
int main(void)
{
int side[n] = { 0 };
char loop = '\0';
do
{
printf("Please enter %d num: ", n);
for (int i = 0; i < n; i++)
scanf("%d", side[i]);
side_rank(*side);
printf("Do you want to run again?(Y,YES N,NO");
scanf("%c", loop);
}
while (loop == 'Y' || loop == 'y');
}
void side_rank(int *a)
{
int i, j, k, s, z;
for (i = n - 1; i >0; i = k)
{
for (j = 0,k=0; j < i; j++)
{
if (*(a + j) > *(a + j + 1))
{
s = *(a + j);
*(a + j) = *(a + j + 1);
*(a + j + 1) = s;
k = j;
}
}
}
for (z = 0; z < n; z++)
{
printf("%5d", *(a + i));
}
} 展开
1个回答
展开全部
#include<stdio.h>
#include <stdlib.h>
#define n 5
void side_rank(int a[]);
int main(void)
{
int side[n] = { 0 };
char loop = '\0';
do
{
int i;
printf("Please enter %d num:",5);
for(i = 0; i < n; i++)
scanf("%d", side[i]);
side_rank(side);
printf("Do you want to run again?(Y,YES N,NO");
scanf("%c", &loop);
}
while (loop == 'Y' || loop == 'y');
}
void side_rank(int *a)
{
int i, j, k, s, z;
for (i = n - 1; i >0; i = k)
{
for (j = 0,k=0; j < i; j++)
{
if (*(a + j) > *(a + j + 1))
{
s = *(a + j);
*(a + j) = *(a + j + 1);
*(a + j + 1) = s;
k = j;
}
}
}
for (z = 0; z < n; z++)
{
printf("%5d", *(a + i));
}
}
更多追问追答
追问
能说一下为什么声明函数的时候要用a〔〕吗
追答
申明用指针也可以。你主要的错误是传入的这个函数的参数形式不对。参数名字前不需要加*号。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询