請問輸出的數字要有空格要怎麼做呢? |
尚未結案
|
tai1688
一般會員 發表:9 回覆:12 積分:4 註冊:2005-03-15 發送簡訊給我 |
#includeOutput: Please enter value (-1 to quit):12.3 Please enter value (-1 to quit):23.3 Please enter value (-1 to quit):34.4 Please enter value (-1 to quit):35.5 Please enter value (-1 to quit):56.7 Please enter value (-1 to quit):45.7 Please enter value (-1 to quit):34.6 Please enter value (-1 to quit):23.5 Please enter value (-1 to quit):-1 How many digits after decimal place ?=>3 8 values were entered These values are: 12.30023.30034.40035.50056.70045.700 34.60023.500請按任意鍵繼續 . . . 他的問題就是輸出的數字都都沒空格,我希望各個輸出的數字要有空格,但我又要保留(How many digits after decimal place ?=>)這個功能該怎ㄇ改呢?~求助各位大大幫忙了感激不盡~^^ |
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
|
tai1688
一般會員 發表:9 回覆:12 積分:4 註冊:2005-03-15 發送簡訊給我 |
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
|
arisaka_matsuri
高階會員 發表:25 回覆:205 積分:231 註冊:2003-10-19 發送簡訊給我 |
dear tai1688:
可以用sprintf產生需要的輸出格式字串(out_str),再交由printf輸出:
char out_str[10]; int digit; printf("How many digits after decimal place ?=>"); scanf("%d", &digit); sprintf(out_str, "%%.ß ", digit); digit = 3, 則out_str會是 %.3f_ (underbar表示space) 顯示就按照你的方式即可 printf(out_str, arr[i]); |
hdilwy
初階會員 發表:18 回覆:65 積分:41 註冊:2004-08-31 發送簡訊給我 |
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrf_iomanip_Setw.asp
希望這個可以滿足你的要求;
另外下面的code是我測試的 你可以試試
#include |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |