標題:

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)); }

免費註冊體驗

 

此文章來自奇摩知識+如有不便請留言告知

其他解答:
文章標籤
創作者介紹
創作者 ute40zf07t 的頭像
ute40zf07t

ute40zf07t的部落格

ute40zf07t 發表在 痞客邦 留言(0) 人氣()