abcdeと入力した際には"YES"
そのほかを入力した際には"NO"
と出力させたいです。
以下のようなコードを書いたのですが、abcde以外の5文字を入力しても"YES"と出力されてしまいます。
解決方法を教えてくださるとありがたいです。
#include <stdio.h> #include <string.h> int main(void){ char str1[] = "abcde"; char str2[256]; int i,no; scanf("%s",str2); no = 0; if(strlen(str2) == 5){ for(i = 0;str2[i]='\0';i++){ if(str1[i] != str2[i]){ no++; } } if(no){ printf("NO"); }else{ printf("YES"); } }else{ printf("NO"); } return 0; }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/16 16:07