How do you print out a specified number of a certain symbol in C programming language?
kerrynet32
2010-06-14 08:40:56 UTC
If I ask the user, "How many '^' symbols would you like to print out?" and they respond, "6", how can I program it to print out "^^^^^^".
Obviously the number they enter could vary, so I dont want you to just say "printf("^^^^^^");"
Four answers:
sicinski
2016-11-29 10:03:56 UTC
Hmm... yet, so some distance as i be conscious of, the only perfect numbers between a million and 1000 are 6, 28, 496. the perfect numbers are below 10 in case you make the main of the selection of unsigned long long.
Chris C
2010-06-14 10:16:15 UTC
A for loop is one way:
for (int i = 0; i < numberToOutput; i++)
printf("^");
Another way would be to define a string that's larger than the entry you allow and printf() only a certain number of items from the string.
char tmpstr[1024];
memset(&tmpstr, '^', 1024);
printf("%*s", numberToOutput, tmpstr);
Here's the printf() function, and I used the "*" width specifier which allows you to pass it to the function call.