1
我寫了這段簡單的代碼(它實際上是根據s,c或t計算x的正弦,餘弦或正切值作爲輸入),它工作正常,直到我試圖改變語句的順序爲止。 。這一個正常工作.....編譯時編譯器跳過語句?
#include<stdio.h>
#include<math.h>
void main()
{
char T;
float x;
printf("\nPress s or S for sin(x); c or C for cos(x); t or T for tan(x)\n\n");
scanf("%c", &T);
printf("Enter the value of x: ");
scanf("%f",&x);
if(T=='s'||T=='S')
{
printf("sin(x) = %f", sin(x));
}
else if(T=='c'||T=='C')
{
printf("cos(x) = %f", cos(x));
}
else if(T=='t'||T=='T')
{
printf("tan(x) = %f", tan(x));
}
}
* 但 *只要我改變安排如下編譯器詢問x的值,並跳過scanf函數對焦炭T和沒有返回值...任何人都可以解釋這裏發生了什麼?
#include<stdio.h>
#include<math.h>
void main()
{
char T;
float x;
printf("Enter the value of x: ");
scanf("%f",&x);
printf("\nPress s or S for sin(x); c or C for cos(x); t or T for tan(x)\n\n");
scanf("%c", &T);
if(T=='s'||T=='S')
{
printf("sin(x) = %f", sin(x));
}
else if(T=='c'||T=='C')
{
printf("cos(x) = %f", cos(x));
}
else if(T=='t'||T=='T')
{
printf("tan(x) = %f", tan(x));
}
}
'無效的主要()'是不是入口點的正確簽名。你正在尋找'int main(void)'。 – 2012-02-10 17:58:38
但前一個運行良好......? – bluedroid 2012-02-10 18:01:41
即使使用int main()它也會跳過第二個scanf ... – bluedroid 2012-02-10 18:04:35