Skip to content

Instantly share code, notes, and snippets.

@ryuchan00
Created April 4, 2020 08:41
Show Gist options
  • Save ryuchan00/a93cdd8ecd1e630a8b249e77f033f245 to your computer and use it in GitHub Desktop.
Save ryuchan00/a93cdd8ecd1e630a8b249e77f033f245 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(void)
{
int i = 0;
// 今は入力値は101を与えてあげる。出力は1が文字列中に2つなので2になる
char *str = "101";
int counter = 0; // strに1が何回あるか数える変数
while (※strの文字列の長さの回数繰り返す)
{
if (※strのi+1文字目が「1」かどうか) { // iは0から開始するが、日本語にすると「i + 1」という表現になる為注意
counter++;
}
i++;
}
printf("%d\n", counter);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment