c语言:输入一个五位整数将数中的五个数值进行从大到小的顺序排序形成一个新的五位整数并输出这个整数。

要求:用函数调用

根据题意得到如下代码:

#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));
}

追问

请问这个程序的作用是什么

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网