2016-10-27 20 views
0

您必須包含哪些代碼才能讓C從輸入到系統中的編號生成輸出。你如何讓C從代碼中輸入的數字產生輸出?

#include <stdio.h> 
int main() 
{ 
    int z; 
    printf("Please enter a number"); 
    return 0; 
} 

我希望程序制定出一個數學方程式於所述用戶輸入,例如數字,如果我輸入5 I希望它的工作超出1的指數2直到該整數輸入。

+0

這裏是關於[輸入一個數字]的小討論(http://stackoverflow.com/questions/21770397/how-to-prompt-the-user-to-enter -a-整數中之一定量-的值)。這必須在你考慮任何計算和輸出之前完成。 –

+2

您發佈的代碼與您描述的問題沒有多大關聯。試過什麼來解決它? –

回答

0

可以使用scanf函數從用戶獲取輸入這樣的:

#include <stdio.h> 
int main() 
{ 
    int z; 
    printf("Please enter a number"); 
    scanf("%d", &z); 

    // do your calculations on z 

    printf("Result: %d", z); 
    return 0; 
} 
0

可以使用scanf函數。

對於一個數字(或在您的情況下的整數特異性)的線是

scanf("%d", &z); 

其中%d指定其中一個整數閱讀和& z是一個指針,指向您的整數變量z。

信息在這裏:https://www.tutorialspoint.com/c_standard_library/c_function_scanf.htm

我猜你是新的C++編程,所以一旦你的基本下跌我建議用指針熟悉自己,因爲他們是語言的一個重要方面。一些有用的資源在這裏使用google-fu:https://www.tutorialspoint.com/cprogramming/c_pointers.htm