c语言输入5个数排列后输出,哪里错了呢?
#include <stdio.h>
#define numlen 5
void delay(int *k, int len)
{
int temp, *b, *c;
for(c = k; c < k+len-1; c++)
for (b=c+1; b < k+len; b++)
if (*c >*b )
{
temp = *c;
*c = *b;
*b = temp;
}
}
int main()
{
int a[numlen],*p;
for(p=a; p < a+numlen; p++)
scanf("%d",p);
delay(a, numlen);
for (p=a; p < a+numlen; p++)
printf("%d", *p);
return 0;
}
//是输入5个字母还是 5个字符串?看你的程序像是五个字符串啊。
12345678910111213141516171819202122232425262728293031323334 //按照5个字母的理解给你写了一个,有问题追问#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ int i, j; char word[5]; char temp; printf("5 words input:"); for (i = 0; i < 5; i++) { scanf("%c", &word[i]); } for (i = 0; i < 5; i++) { for (j = 0; j < 5-i-1;j++) { if (word[j]>word[j+1]) { temp=word[j]; word[j]= word[j+1]; word[j+1]=temp; } } } printf("outputting after ordering:"); for (i = 0; i < 5; i++){ printf("%c",word[i]); } getchar(); getchar(); getchar();}
下一篇:下单接龙小程序怎样操作?
上一篇:Hello.c可执行程序的生成