fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7. int ans, a=50, s,b=50;
  8.  
  9. srand( time(0) );
  10.  
  11. ans = rand()%100; // 乱数を生成し100で割った余りを求める
  12. // つまり、乱数で0以上99以下の整数を生成
  13.  
  14. do
  15. {
  16. printf("%d",a);
  17.  
  18.  
  19. if ( a <= ans-10 ){
  20. printf("とても小さいです。\n");
  21. s=1;
  22. }
  23. else if( a < ans ){
  24. printf("小さいです\n");
  25. s=1;
  26. }
  27. else if( a>=ans+10){
  28. printf("とても大きいです\n");
  29. s=2;
  30. }
  31. else if(a>ans){
  32. printf("大きいです\n");
  33. s=2;
  34. }
  35. b=b/2;
  36. if(b==0){
  37. b++;
  38. }
  39. if(s==1){
  40. a=a+b;
  41. }
  42. if(s==2){
  43. a=a-b;
  44. }
  45. }
  46. while( a!=ans );
  47.  
  48. printf("正解です!!!\n");
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
50とても小さいです。
75とても大きいです
63大きいです
57小さいです
60小さいです
正解です!!!