Question

I'm taking a C programming class and I've been just playing around with the code (very...

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!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

Add a comment
Know the answer?
Add Answer to:
I'm taking a C programming class and I've been just playing around with the code (very...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT