アプリ版:「スタンプのみでお礼する」機能のリリースについて

画像の赤い線の部分に適切なプログラムを入れて正の整数xを入力すると2^xを表示するようにしたいのですが何を入れればよいのかわかりません。教えていただけないでしょうか。

「2^xを表示するプログラミング」の質問画像

A 回答 (3件)

#include <stdio.h>


#include <stdlib.h>

int main(void) {
 char s[2];
 scanf("%1s%*[^\n]", s);
 getchar();
 printf("%d\n", 2 << (strtol(s, NULL, 10) - 1));
 return EXIT_SUCCESS;
}
    • good
    • 0

#include <stdio.h>


#include <stdlib.h>
#include <math.h>

int main(void) {
 int x;
 char s[2];
 scanf("%1s%*[^\n]", s);
 x = strtol(s, NULL, 10);
 printf("%d\n", (int)pow(2, x));
 return EXIT_SUCCESS;
}
    • good
    • 0

x回繰り返して mに2をかけた結果を保存すればOKですよ。

    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!