close
標題:
Programming problem in C
發問:
Q.1 If i want to display the % sign ina printf statment, what can I do? for examp: i want to display 8.2% in the screen. Q2 If I have a memory constant called TAX in main , can I use it directly in the function that I created. The compiler said there is error when I use the constant like this..
最佳解答:
Q.1 double a=8.2; printf("%.1f%%\n",a); Q.2 Method 1: define TAX to be replaced by 15.0 by the C precompiler #define TAX (15.0) double abc(){ double a=TAX*100; return a; } int main(....){ printf(....., abc()); } method 2: put TAX as a global variable (visible by all modules) #include ..... double TAX; double abc(){ double a=TAX*100; return a; } int main(....){ TAX=15.0; printf(....., abc()); } method 3: use TAX as a formal parameter double abc(double x){ double a=x*100; return a; } int main(....){ double TAX=15.0; printf(....., abc(TAX)); }
Programming problem in C
發問:
Q.1 If i want to display the % sign ina printf statment, what can I do? for examp: i want to display 8.2% in the screen. Q2 If I have a memory constant called TAX in main , can I use it directly in the function that I created. The compiler said there is error when I use the constant like this..
最佳解答:
Q.1 double a=8.2; printf("%.1f%%\n",a); Q.2 Method 1: define TAX to be replaced by 15.0 by the C precompiler #define TAX (15.0) double abc(){ double a=TAX*100; return a; } int main(....){ printf(....., abc()); } method 2: put TAX as a global variable (visible by all modules) #include ..... double TAX; double abc(){ double a=TAX*100; return a; } int main(....){ TAX=15.0; printf(....., abc()); } method 3: use TAX as a formal parameter double abc(double x){ double a=x*100; return a; } int main(....){ double TAX=15.0; printf(....., abc(TAX)); }
此文章來自奇摩知識+如有不便請留言告知
其他解答:文章標籤
全站熱搜
留言列表