Write a program that asks a user for an input string and thenprints it out in th
ID: 3615497 • Letter: W
Question
Write a program that asks a user for an input string and thenprints it out in the following radial manner. The last letter ofthe word should be at the center of the printout. Horizontally,vertically, and along each diagonal, the word should be printedstarting from the outside and ending with the last letter in themiddle. For example, for the word "cat", the output should looklike:c c c
aaa
catac
aaa
c c c
For the word "frog" , the output should look like:
f f f
r r r
ooo
frogorf
r r r
f f f
Program correctness is important, but the following organizationtools should be applied appropriately. The program should usepreprocessing to define a maximum word size and to test its correctusage by the user. Comments should be used, at an appropriate levelof detail, to describe the method(s) for storing and/or displayingthe radial printout.
Explanation / Answer
//Hope this will helpyou.#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char str[100]; int len,i,j,k; printf("Enter string :"); scanf("%s",str); len = strlen(str);
for(i=0;i<len;i++) { if(i!=len-1) { for(j=0;j<i;j++) printf(" "); }else { for(j=0;j<i-len-1;j++) printf(" "); } if(i!=len-1) { for(k=0;k<3;k++) { printf("%c",str[i]); for(j=0;j<(len-i-2)>0?(len-i-2):0;j++) printf(" "); } }else { printf("%s",str); for(j=len-2;j>=0;j--) printf("%c",str[j]); } printf(" "); }
for(i=len-2;i>=0;i--) { if(i!=len-1) { for(j=0;j<i;j++) printf(" "); }else { for(j=0;j<i-len-1;j++) printf(" "); } if(i!=len-1) { for(k=0;k<3;k++) { printf("%c",str[i]); for(j=0;j<(len-i-2)>0?(len-i-2):0;j++) printf(" "); } }else { printf("%s",str); for(j=len-2;j>=0;j--) printf("%c",str[j]); } printf(" "); } system("pause"); }
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char str[100]; int len,i,j,k; printf("Enter string :"); scanf("%s",str); len = strlen(str);
for(i=0;i<len;i++) { if(i!=len-1) { for(j=0;j<i;j++) printf(" "); }else { for(j=0;j<i-len-1;j++) printf(" "); } if(i!=len-1) { for(k=0;k<3;k++) { printf("%c",str[i]); for(j=0;j<(len-i-2)>0?(len-i-2):0;j++) printf(" "); } }else { printf("%s",str); for(j=len-2;j>=0;j--) printf("%c",str[j]); } printf(" "); }
for(i=len-2;i>=0;i--) { if(i!=len-1) { for(j=0;j<i;j++) printf(" "); }else { for(j=0;j<i-len-1;j++) printf(" "); } if(i!=len-1) { for(k=0;k<3;k++) { printf("%c",str[i]); for(j=0;j<(len-i-2)>0?(len-i-2):0;j++) printf(" "); } }else { printf("%s",str); for(j=len-2;j>=0;j--) printf("%c",str[j]); } printf(" "); } system("pause"); }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.