湿度を表示してみましょう。
#include <stdio.h>
int main(void) {
int x = 10;
printf("今日の湿度は%d%です\n", x);
return 0;
}
このように書くと%d%のところでエラーが出てしまいます。
このエラーの解決策は下記のように%を%%とすることです。
#include <stdio.h>
int main(void) {
int x = 10;
printf("今日の湿度は%d%%です\n",x);
return 0;
}
基本ではありますが、しばらくc言語から離れていると忘れがちな記法だと思います。
似たような例題とその解答を下に置いておきます。
間違いがあればコメントしていただけると嬉しいです。
<例題1>
二つの整数値を読み込んで、前者の値が後者の値の何%であるかを整数で表示するプログラムを作成せよ。
#include <stdio.h>
int main(void) {
int x, y;
puts("二つの整数を入力してください。");
printf("整数x:"); scanf("%d", &x);
printf("整数y:"); scanf("%d", &y);
printf("xの値はyの%d%%です\n", x * 100/ y);
return 0;
}