2015-06-17 49 views
0

我需要顯示在輸出時前乘法的過程中提供幫助: - 輸入兩個數字(325說4405) 輸出將是: -需要寫這個乘法代碼

325 
    *4405 
    ----- 
    1625 
    0 
1300 
1300 
------- 
1431625 

注意: - 空格的數量應該最小。

我不需要確切的代碼。 只要告訴我哪個屬性或方式我應該用來獲得每一行中的SPACE權限,或者我應該如何繼續獲得輸出。

+0

下面是關於使用*** [printf的格式說明的教程](http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output)*** in C.(not down down voter)特別要注意的例子有'printf (「%03d \ n」,b);'(提供數值前的前導空格 – ryyker

+0

非常感謝@ryyker。正在尋找某物o這種類型,但是無法找到它。但是當輸入變化時如何去做呢?當每個輸入中的空格都不可變時) –

+0

數字是如何輸入的?通過用戶輸入使用scanf()?,從文件中讀取?如果作爲一個字符串,你可以使用strlen()來知道最終將被轉換爲數字的長度。或者,如果使用數字值,則可以測試範圍:if(x <10)else if((x> = 10)&&(x <100)else if ...' – ryyker

回答

0

下面是如何用printf使恆定長度的打印輸出的簡單示例:

int main(void) 
{ 

    char a[6][7]={"1","22","333","4444","55555","666666"}; 
    int i; 
    int value; 

    for(i=0;i<sizeof(a)/sizeof(a[0]);i++) 
    { 
     value = atoi(a[i]); 
     printf("%07d\n", value); //with leading zeros 
     printf("% 7d\n", value); //with spaces 
    } 

    getchar(); 
    return 0; 
} 

這裏是輸出:
enter image description here

+0

感謝@ryyker非常感謝您的幫助。我認爲我現在可以做到。 –