//已知线性表按照顺序存储,且每个元素都是互不相等的整数,设计把所有奇数移到所有偶数前边的程序;
#include<stdio.h>#defineMAXSIZE100typedefstruct{intdata[MAXSIZE];intlen;}sqlist;intma...
#include<stdio.h>
#define MAXSIZE 100
typedef struct
{
int data[MAXSIZE];
int len;
}sqlist;
int main()
{
sqlist A;
int temp,k,j;
scanf("%d",&A.len);
for(k=0;k<A.len;k++)
scanf("%d",&A.data[k]);
k=0;
j=A.len-1;
while(k<=j)
{
while(A.data[k]%2==0) k++;
while(A.data[k]%2==1) j--;
if(k<j)
{
temp=A.data[k];
A.data[k]=A.data[j];
A.data[j]=temp;
}
}
for(k=0;k<A.len;k++)
printf("%d ",A.data[k]);
return 0;
}
为什么出不来答案啊!?急急急!!! 展开
#define MAXSIZE 100
typedef struct
{
int data[MAXSIZE];
int len;
}sqlist;
int main()
{
sqlist A;
int temp,k,j;
scanf("%d",&A.len);
for(k=0;k<A.len;k++)
scanf("%d",&A.data[k]);
k=0;
j=A.len-1;
while(k<=j)
{
while(A.data[k]%2==0) k++;
while(A.data[k]%2==1) j--;
if(k<j)
{
temp=A.data[k];
A.data[k]=A.data[j];
A.data[j]=temp;
}
}
for(k=0;k<A.len;k++)
printf("%d ",A.data[k]);
return 0;
}
为什么出不来答案啊!?急急急!!! 展开
3个回答
展开全部
while(A.data[k]%2==0) 改成while(k<=j&&A.data[k]%2==0)
while(A.data[k]%2==1) 改成while(k<=j&&A.data[j]%2==0)
while(A.data[k]%2==1) 改成while(k<=j&&A.data[j]%2==0)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
typedef int ElemType;
typedef struct
{
ElemType data[MAXSIZE];
int len;
} SqList;
void main()
{
SqList sqa; int i,j,temp;
for (i = 0; i<8; i++) { printf("enter the list"); scanf_s("%d", &sqa.data[i]); }
sqa.len = 8;
i = 0;
j = sqa.len - 1;
while (i <= j)
{
while (sqa.data[i] % 2 == 0)i++;
while (sqa.data[j] % 2 == 1)j--;
if (i < j)
{
temp = sqa.data[i];
sqa.data[i] = sqa.data[j];
sqa.data[j] = temp;
}
}
printf("data of sqc:\n");
for (i = 0; i<sqa.len; i++) printf("%5d", sqa.data[i]);
system("pause");
system("pause");
}
#include<stdlib.h>
#define MAXSIZE 100
typedef int ElemType;
typedef struct
{
ElemType data[MAXSIZE];
int len;
} SqList;
void main()
{
SqList sqa; int i,j,temp;
for (i = 0; i<8; i++) { printf("enter the list"); scanf_s("%d", &sqa.data[i]); }
sqa.len = 8;
i = 0;
j = sqa.len - 1;
while (i <= j)
{
while (sqa.data[i] % 2 == 0)i++;
while (sqa.data[j] % 2 == 1)j--;
if (i < j)
{
temp = sqa.data[i];
sqa.data[i] = sqa.data[j];
sqa.data[j] = temp;
}
}
printf("data of sqc:\n");
for (i = 0; i<sqa.len; i++) printf("%5d", sqa.data[i]);
system("pause");
system("pause");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把上面的0改为1,然后把1改为0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询