Printing multiple integers can be done easily!!

WRONG : Console.WriteLine("%d * %d = %d",c,a,b);
***
RIGHT AND PERFECT:: Console.WriteLine("{0} * {1} = {2}",c,a,b);***

Recommended Answers

All 4 Replies

I should have written that in FORTRAN and say that it is WRONG in C#.

C# is mentioned!

WRONG : Console.WriteLine("%d * %d = %d",c,a,b);

Of course it's wrong, WriteLine() does not and never has purported to offer printf() style format specifiers. Saying that the above code is wrong is just like saying that the following line is wrong:

Console.WriteLine("FORMAT INT #1 LITERAL(*) INT #2 LITERAL(=) INT #3", c, a, b);

It's not even worth mentioning, because it's obvious to anyone who bothered to read a book or reference on C#. Of course, if your taget audience is the folks who learn by random guessing, then it might be helpful.

RIGHT AND PERFECT:: Console.WriteLine("{0} * {1} = {2}",c,a,b);

Actually, I'd wager that your right and perfect answer is actually incorrect. If it's not incorrect, it's misleading because the usual convention is for c to contain the result of a binary operation:

Console.WriteLine("{0} * {1} = {2}", a, b, c);
commented: Well said. +0

A straightforward solution to printing multiple integers is to use a loop. For example, in Python, you could use a "for" loop to iterate through a list of integers and print each one. This method is simple and effective.

commented: 10 years late? -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.