Char repeat in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Char repeat in c

Input = hello Output = hhheeellllllooo Can someone explain me the logic as to how to implement it.

9th May 2020, 2:37 AM
Saaquib Motiwala
3 Answers
+ 3
#include <stdio.h> #include<string.h> int main() { char b[100]; int i, a; scanf("%d",&a); scanf("%s",b); for(i=0;i<a;i++) { printf("%c",b[i]); printf("%c",b[i]); printf("%c",b[i]); } return 0; } This is the code and it works perfectly 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Thanks
9th May 2020, 3:36 AM
Saaquib Motiwala
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 What if a number is not given (in this case 3)? What if the repeat rate is to be initialized at runtime?
9th May 2020, 3:41 AM
Saaquib Motiwala
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Means using nested for loop right
9th May 2020, 3:52 AM
Saaquib Motiwala