IvoSilva

[PROG1] Ficha 5 | Exercício 6

Nov 17th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. void rect (char c , int nlinhas , int ncolunas)
  3. {
  4.     int i , j ;
  5.     for (i = 0 ; i < ncolunas ; i++) printf ("%c" , c) ;
  6.     printf ("\n") ;
  7.     for (i = 0 ; i < nlinhas - 2 ; i++)
  8.     {
  9.         for (j = 0 ; j < ncolunas ; j++)
  10.         if (j == 0 || j == ncolunas - 1) printf ("%c" , c) ;
  11.         else printf (" ") ;
  12.         printf ("\n") ;
  13.     }
  14.     for (i = 0 ; i < ncolunas ; i++) printf ("%c" , c) ;
  15.     printf ("\n") ;
  16. }
  17. int main ()
  18. {
  19.     char c ;
  20.     int nlinhas , ncolunas ;
  21.     printf ("Introduza um caracter: ") ;
  22.     scanf ("%c" , &c) ;
  23.     printf ("Introduza o numero de linhas: ") ;
  24.     scanf ("%d" , &nlinhas) ;
  25.     printf ("Introduza o numero de colunas: ") ;
  26.     scanf ("%d" , &ncolunas) ;
  27.     rect(c , nlinhas , ncolunas) ;
  28.     return 0 ;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment