要求:用函数调用
根据题意得到如下代码:
#include <stdio.h>int getMaxFive(int n)
{
int a[5], i, j, k = 0, t;
while (n!=0){
a[k] = n%10;
n /= 10;
k++;
}
if (k != 5)return -1;
for (i = 0; i < k; ++i){
for (j = 0; j < k-i-1; ++j){
if (a[j] < a[j+1]){
t = a[j], a[j] = a[j+1], a[j+1] = t;
}
}
}
t = 0;
for (i = 0; i < k; ++i){
t = t*10 + a[i];
}
return t;
}
int main()
{
int e = getMaxFive(82731);
printf ("%d\n", e);
return 0;
}追问
第一个函数里while语句里是什么作用
追答求这个五位数的每一位数字
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-09-13
#include <stdio.h>
struct student
{
char name[15];
struct student *next;
};
struct student *link(struct student *a, struct student *b) {
struct student *p = a;
while (p->next)
p = p->next;
p->next = b; // p->next = b->next; 这里你确定链表是有头指针还是没有头指针吗?
return a;
}
int main() {
struct student stu1, stu2;
stu1.next = NULL;
stu2.next = NULL;
scanf("%s %s", stu1.name, stu2.name);
printf("%s", link(&stu1, &stu2));
}追问
struct student
{
char name[15];
struct student *next;
};
struct student *link(struct student *a, struct student *b) {
struct student *p = a;
while (p->next)
p = p->next;
p->next = b; // p->next = b->next; 这里你确定链表是有头指针还是没有头指针吗?
return a;
}
int main() {
struct student stu1, stu2;
stu1.next = NULL;
stu2.next = NULL;
scanf("%s %s", stu1.name, stu2.name);
printf("%s", link(&stu1, &stu2));
}追问
请问这个程序的作用是什么