Connecting Tech Pros Worldwide Forums | Help | Site Map

Using printf to print a value multiple times

Nick Li
Guest
 
Posts: n/a
#1: Nov 13 '05
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

Mac
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Using printf to print a value multiple times


On Sun, 24 Aug 2003 14:01:52 +0000, Nick Li wrote:
[color=blue]
> 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[/color]


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
--
Closed Thread