473,388 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Using printf to print a value multiple times

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
1 12593
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary Harvey | last post by:
I have a data intensive program that requires all data to be present in memory. I keep running out of memory at about 2G whenever I run my program. I tried using a 64 bit version of Perl and hit...
3
by: Paul Watson | last post by:
It is clear that just using 'print' with variable names is relatively uncontrollable. However, I thought that using a format string would reign the problem in and give the desired output. Must...
3
by: ehabaziz2001 | last post by:
I know one of the pointer benefit is that we can return more than one value from a function . The down program has an error that I can not discover . That is the call of the function : The Call:...
52
by: mavic | last post by:
hi to everybody,i need help for my project....how to make a program that accept any integer and convert it binary,octal and hexadecimal.pls help me...thanks
2
by: B Garner | last post by:
Hi all Help please. I would like to automate the printing of a report. The report actually is a single page and prints a label. I would like to be able to print the report multiple times...
7
by: wardm | last post by:
I have created a Dict object in a C++ App that calls (embedded) Python functions. The Dict is to be used to pass variable data between the C++ App and the python functions. However I cannot get...
3
by: cachaco87 | last post by:
Hi, I'm new to this boards, and I need some help finishing a project for school. Im using nested if-statements inside a while loop to execute different actions. action C consist of printing the...
0
by: raghuveer | last post by:
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have #include<stdio.h>...
15
by: Ioannis Vranos | last post by:
I recall from previous discussions here, that we must cast a non-void pointer to void * before printing its value with printf("%p"). Is it true, and if yes why?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.