Files
CWithClasses/C/BasicSyntax/ctest.cpp
2025-12-31 00:39:23 +08:00

27 lines
532 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
/*
printf中%d的妙用
%5d:宽度5右对齐空格补
%05d(%.5d)宽度5右对齐0补
%-5d宽度5左对齐空格补→不能写%-.5d
printf中%c,%s的妙用
%.2s:输出前两位
*/
int main(){
double a=2,b=4;
a/=3;
b/=7;
printf("double:\na = %04.2f%%, b = %55.50f%%\n",a,b);
printf("a = %07f, b = %08f\n",a,b);
int c=345;
printf("int:\nc = %.6d\n",c);
printf("c = %05d\n",c);
printf("c = %-5d\n",c);
double f=123456;
printf("e:\nf = %10.2e\n",f);
char d[]="canyoukissmyass";
printf("string:\n%.2s\n",d);
return 0;
}