fork(5) download
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6. char str[50];
  7. char str2[50][50];
  8. int lenstr;
  9. int i,j;
  10. char temp;
  11.  
  12. printf("Enter the string :\n");
  13. scanf("%s",str);
  14. lenstr = strlen(str);
  15. if(lenstr %2 == 0)
  16. {
  17. printf("The string length must be an odd length");
  18.  
  19. }
  20. else
  21. {
  22. j = 0;
  23. temp = 0;
  24.  
  25. for(i = 0;i<lenstr;i++)
  26. for(j = 0;j<lenstr;j++)
  27. str2[i][j] = ' ';
  28.  
  29. for(i = 0;i < lenstr;i++)
  30. {
  31. str2[i][i] = str[i];
  32. str2[i][lenstr- i -1] = str[i];
  33. }
  34. /*
  35.   for(i = lenstr; i!=0 ;i--)
  36.   {
  37.   j = lenstr;
  38.   str2[i][j] = str[temp];
  39.   temp = temp + 1;
  40.   j = j - 1;
  41.  
  42.   }
  43.   */
  44. for(i = 0;i<lenstr;i++)
  45. {
  46.  
  47. for(j = 0;j<lenstr;j++)
  48. {
  49. printf("%c",str2[i][j]);
  50. }
  51. printf("\n");
  52. }
  53.  
  54. }
  55.  
  56. return 0;}
Success #stdin #stdout 0s 2012KB
stdin
ghosh
stdout
Enter the string :
g   g
 h h 
  o  
 s s 
h   h