By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Using printf to print a value multiple times

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mac
On Sun, 24 Aug 2003 14:01:52 +0000, Nick Li wrote:
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
--
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.