#include <stdio.h>
int main()
{
int a,b,n,c;
float d;
scanf("%d,%d,%d",&a,&b,&n);
c=a-b;
d=(float)c/a*100 ;
printf("%*d\n%*d\n%6.2f%%",n,c,n,a,d);
return 0;
}
输入99,4,5
想要95
99
95.96%这样的格式
但是%d输出后好像会有空格
所以成了95
99
95.96%这样子,不知道该怎么办了,求大神指点!
加负号,表示左对齐
#include <stdio.h>
int main()
{
int a,b,n,c;
float d;
scanf("%d,%d,%d",&a,&b,&n);
c=a-b;
d=(float)c/a*100 ;
printf("%-*d\n%-*d\n%-6.2f%%",n,c,n,a,d);
return 0;
}