2 solutions

  • 0
    @ 2023-11-23 22:44:54
    #include <stdio.h>
    int main()
    {
    	double sn = 0 * 1.0, d;
        int k, i = 1;
    	scanf("%d", &k);
    	while (sn <= k)
    	{
    		d = 1.0 / i;
    		sn += d;
    		i++;
    	}
    	printf("%d", i - 1);
    	return 0;
    }
    /*各位佬能不能看一下我为什么输出i - 1正确,输出i不正确*/
    
    • 0
      @ 2023-10-25 15:40:04
      #include<math.h>
      #pragma warning(disable:4996) 
      int main()
      {
          int k, n = 1;
          double sum = 0;
          scanf("%d", &k);
          do
          {
              sum = sum + 1.0 / n;
              n++;
          } while (!(sum > k));
          printf("%d", n-1);
          return 0;
      }
      
      • 1

      Information

      ID
      6753
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      7
      Tags
      (None)
      # Submissions
      407
      Accepted
      79
      Uploaded By