I am writing a program in C that first prompts the user for an integer , then prints two strings: a blank space and a # on a variable number so that the result would be a right sided pyramid, like this:
#
##
###
####
#####
######
The problem i have resides in my for loop, here's what it looks like :
(n is the integer that the user prompts)
for (int i = 0 ; i < n ; i++)
{
printf("%c",n-1,' '); // printing the blank spaces gradually
printf("%c\n",i+2,'#'); // printing the hashes gradually
}
The idea is to print an decreasing number of spaces and an increasing number of hashes depending on the int.
P.S : Please consider helping me by saying what is wrong with my code, not giving me an actual new working one.
printfcalls actually print the value of(char)(n - 1)or(char)(i+ 2)once and ignores the remaining arguments. Whatever makefile you're using, you should include-Wallin yourccline at the very least if your compiler supports it (or investigate the options your compiler has for turning up warnings/warning levels) and-Wextraif possible. That will catch a lot of coding mistakes these days, such as unusedprintfarguments. A common solution is a loop inside your current loop that printsn - i - 1spaces followed by another loop after that to print '#'itimes.%cexpects to match a character, not a number of items