C 获取我的双精度的wierd值

C 获取我的双精度的wierd值,c,printf,scanf,C,Printf,Scanf,在scanf中的p和q中键入值,然后在printf中键入值,得到了荒谬的值。为什么? printf的%d格式说明符需要int类型参数,传递任何其他类型都是未定义的行为 请尝试使用%f打印双精度打印。1f应该是%lf,而%d应该是%f。printf和scanf的文档有什么不清楚的地方吗?更改它,但仍然不起作用,我在debugg中查看步骤,并在我的p%f上获得了类似于&p 0x00c6a140{labb3e.exe!double p}{5.356796015279e-315DEN double的值以

在scanf中的p和q中键入值,然后在printf中键入值,得到了荒谬的值。为什么?

printf的%d格式说明符需要int类型参数,传递任何其他类型都是未定义的行为


请尝试使用%f打印双精度打印。

1f应该是%lf,而%d应该是%f。printf和scanf的文档有什么不清楚的地方吗?更改它,但仍然不起作用,我在debugg中查看步骤,并在我的p%f上获得了类似于&p 0x00c6a140{labb3e.exe!double p}{5.356796015279e-315DEN double的值以打印双精度打印?不应该是%lf吗?@J…S文档很清楚:两者都是有效的兼容性原因,不能将浮点作为可变参数传递。
void gyllenSnitten(void);
void Andragradare(void);

double p,q;
double root1, root2;

void main()
{
    gyllenSnitten();
    Andragradare();
}

void gyllenSnitten(void){
    printf("Gyllende snittet är %d..\n",(1+sqrt(5))/2)
}

void Andragradare(void){

   system("cls");

   printf("P-q formeln,\n");
   printf("Choice youre P \n");

   scanf_s("%1f",&p);
   printf("Choice youre Q\n");
   printf("%1f", &q);

   root1 = (-p / 2) + sqrt(((p / 2)*(p / 2)) + q);
   root2 = (-p / 2) - sqrt(((p / 2)*(p / 2)) + q);

   printf("Here is the first X = %d",root1);
   printf("and the other onehere  X = %d",root2);

   _getch();
}