Advertisement
Jvsierra

String triângulo

Jun 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. #define LIM 51
  6.  
  7. int main()
  8. {
  9.     int i, distanciaEsq, distanciaDir, pos, diminui;
  10.     char str[LIM], j;
  11.    
  12.     fflush(stdin);
  13.     gets(str);
  14.    
  15.     distanciaEsq = strlen(str) * 2;
  16.     j = 0;
  17.    
  18.     for(i = 0; i < distanciaEsq; i++)
  19.     {
  20.         printf(" ");
  21.     }
  22.    
  23.     pos = 0;
  24.    
  25.     printf("%c\n", str[pos]);
  26.    
  27.     pos++;
  28.     distanciaDir = distanciaEsq;
  29.    
  30.     while(pos < strlen(str) - 1)
  31.     {
  32.         distanciaDir+=2;
  33.         distanciaEsq-=2;
  34.        
  35.         for(i = 0; i < distanciaEsq; i++)
  36.             printf(" ");
  37.            
  38.         printf("%c", str[pos]);
  39.        
  40.         for(i = distanciaEsq; i < distanciaDir; i++)
  41.             printf(" ");
  42.            
  43.         printf("%c", str[pos]);
  44.        
  45.         printf("\n");
  46.            
  47.         pos++;
  48.     }
  49.    
  50.     for(i = 0; i < distanciaEsq - 1; i++)
  51.         printf(" ");
  52.        
  53.     diminui = 1;
  54.        
  55.     pos = strlen(str) - 1; 
  56.        
  57.     while(pos <= strlen(str) - 1)
  58.     {  
  59.         printf("%c ", str[pos]);
  60.        
  61.         if(pos == 0)
  62.             diminui = 0;
  63.        
  64.         if(diminui == 1)
  65.             pos--;
  66.         else
  67.             pos++;
  68.     }
  69.    
  70.     getch();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement