Programming problem in C

2006-10-16 4:49 pm
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..

回答 (1)

2006-10-16 5:13 pm
✔ 最佳答案
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));
}


收錄日期: 2021-04-12 20:07:10
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061016000051KK00676

檢視 Wayback Machine 備份