如何关闭 C 中的指数表示法?

How can I turn off Exponenntial Notation in C?

please enter num1 , op , num2
2e2+6
result= 206.000000

Process returned 0 (0x0)   execution time : 8.657 s
Press any key to continue.

(如何使用)...任何关闭它的方法!

您不能直接执行此操作,scanf 函数族没有标准格式说明符拒绝 float 或 [=14= 的科学记数法(例如 1e3) ] 并且没有直接的方法 "turn off" scanf 接受科学记数法中的数字。

您可以将输入读取为字符串。然后检查字符串是否包含 'E' 或 'e',如果是则拒绝。

这种天真的方法应该让您知道您可以做什么:

#include <stdio.h>
#include <string.h>

int main()
{
  float x = 0;

  do
  {
    char buffer[100];
    scanf("%s", buffer);

    if (strchr(buffer, 'E') != NULL || strchr(buffer, 'e') != NULL)
    {
      printf("Rejected\n");
    }
    else
    {
      sscanf(buffer, "%f", &x);
      break;
    }
  } while (1);
  //...
}

除了明确检查是否存在 Ee,您还可以检查是否存在任何非数字和非小数点字符,如果缓冲区包含以下任何内容,IOW 将拒绝[0123456789.]

中未包含的字符

当然你最终应该把这个功能放到一个函数中。