对于C编程.如何将数字显示为00,01,02,03,而不是0,1,2,3.我只需要在数字前需要0,直到10.
我知道当你做小数时你可以做"%.2f"等但是对于整数反过来怎么样?
这是我正在使用的......**
printf("Please enter the hours: ");
scanf ("%d",&hour);
printf("Please enter the minutes: ");
scanf ("%d",&minute);
printf("Please enter the seconds: ");
scanf ("%d",&second);
printf("%d : %d : %d\n", hour, minute, second);
Run Code Online (Sandbox Code Playgroud)
}
我需要将数字显示为00:00:00
??
所以我做了一个结构,我在一个函数内部调用它,但事情进展不顺利......
结构如下......
结构功能
struct Line {
private:
int lineNumber;
char lineString[];
public:
bool set(int n,const char* str);
void display() const;
};
Run Code Online (Sandbox Code Playgroud)
一切都在函数内正常工作,我存储了lineN和lineS然后将它们发送到名为... bool set(int n,const char*str)的函数中 ; (从上面)使用名为storage的结构.在第一个while循环之后,我使用了一个名为display的函数来显示lol.
设定功能
void List::set(int no){
Line storage[no];
int i =0, x;
while (i!=no){
cout << "Enter line number : ";
cin >> lineN;
cout << "Enter line string : ";
cin >> lineS;
x = storage[i].set(lineN, lineS);
if (x == 1){
i++;
}
}
i=0;
while (i!=no){
storage[i].display();
i++;
}
} …Run Code Online (Sandbox Code Playgroud)