The author has 1 post.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
919 0
【试题】2的次幂表示
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 4/16/16 21:24
#include <stdio.h>

void output(int n)
{
    int i;
    int first = 1;
    for (i = 15; i >= 0; i--)
    {
        if (n & (1 << i))
        {
            if (first)
                first = 0;
            else
                putchar('+');
            if (i == 1)
                putchar('2');
            else if (i == 0)
                printf("2(0)");
            else
            {
                printf("2(");
                output(i);
                putchar(')');
            }
        }
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    output(n);
    putchar('\n');
    return 0;
}
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 919 Replies: 0
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 4/16/16 21:24
Announcements