10進數的數字,怎樣用文字型表示,比如123這個數字用char a[3]的表示的話,a[0]=1, a[1]=2,a[2]=3.
- 2022-08-09
#include <;stdio。h>;
#define N 20 // 3 is too short for double
typedef struct{
char a[N];
}PER;
PER assign(double num)
{
PER a;
sprintf(a。a,“%lf”,num);
return a;
}
void print(PER c)
{
printf(“%s”, c。a ); // format %s
}
int main(void)
{
PER d;
d = assign(123);
print(d);
}