Using printf to print a value multiple times

N

Nick Li

Hi,

I am trying to print a value of a variable multiple times. For
example, the value is "*" and I want to print it five times, like
"*****". Can somebody show me a easy way to do it?

Thanks in advance.

Nick
 
M

Mac

Hi,

I am trying to print a value of a variable multiple times. For
example, the value is "*" and I want to print it five times, like
"*****". Can somebody show me a easy way to do it?

Thanks in advance.

Nick


Well, what have you tried? Do you have any ideas? You'll never learn if
you don't try.

I'll give you a hint, though. If you know how to printf a variable once,
and you know how to use a for loop, then you should be able to printf a
variable however many times you want.

Here is a simple for loop example:

#include <stdio.h>

int main(void)
{ int i;
int sum=0;

for (i=0; i<5; i++)
sum = sum+i;
printf("Sum = %d\n", sum);
return 0;
}

I Hope That Helps (HTH).

Mac
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top