Hi thereI'm learning C language and i am so new in this world. so i have two problems the first one is i need to print a char two times in a line without using printf twice and i used this code:

Code:

#include <stdio.h>

int main(void){ char chr = 'a'; printf("%2c\n", chr); return 0;}

as you know the %2 won't print 'a' two times it will show it like this in output " a" (with 2 spaces at first) and it is not bad i will need it toobut i need to declare a variable for it instead of %2 i need something like this:

You can do this in many, many different ways. Here are two working examples:

Code:

#include <stdio.h>

int main(void){ char chr = 'a';

for(int i=0; i<2; i++) { printf("%c", chr); }

return 0;}

Loops twice and there prints the value of 'chr' twice. Notice I removed the the new line character "\n" (which you can add later)

Code:

#include <stdio.h>

int main(void){ char chr = 'a'; printf("%c%c", chr, chr);

return 0;}

Another variation, without the loop.

I used to teach C and C++ at a College. So I would be happy to give you a hand!

Hi there whats up? Man for my program maybe i need to print it more than 1000 times two was an exmaple so loop is better but i need to use another loop too so it may cause some confilict too any way what about the second one? Thx so much