I'm taking a C programming class and I've been just playing around with the code (very beginner stuff!) and I was trying to figure out how to add something in the middle of a printf(). What I was trying to do was put a $ symbol in front of an amount while setting the width and precision at the same time, but I'm finding myself stumped and there's nothing in the textbook that discusses it. More just curiosity on my part than anything else.
current code is as follows:
int main()
{
double n1 = 4.5;
printf("%8.2f\n", n1);
system ("pause");
}
Nothing fancy really, but I just wondered if it's even possible. Thanks!
You can directly add that in the printf statement. After adding it will look like this
int main()
{
double n1 = 4.5;
printf("$%8.2f ", n1);
//system ("pause");
}
Output:
I'm taking a C programming class and I've been just playing around with the code (very...