Advertisement
What_Ever

Untitled

Dec 20th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. void printPattern(int n,int maxN);
  3. int main()
  4. {
  5.     int n;
  6.     printf("Enter the Number of asterisks: ");
  7.     scanf("%d",&n);
  8.     if(n < 1)
  9.     {
  10.         printf("error! the number of lines can\'t be negative");
  11.         return 1;
  12.     }
  13.     int numberOfLines = 2*n-1;
  14.     printPattern(numberOfLines,n);
  15.     return 0;
  16. }
  17. void printPattern(int n,int maxN)
  18. {
  19.     if (n >= maxN)
  20.     {
  21.         for(int i = n ; i < 2*maxN; i++ )
  22.         {
  23.             printf("*");
  24.         }
  25.         printf("\n");
  26.         printPattern(n-1,maxN);
  27.     }
  28.     else if(n >= 1)
  29.     {
  30.         for(int i = n;i >=1 ; i--)
  31.         {
  32.             printf("*");
  33.         }
  34.         printf("\n");
  35.         printPattern(n-1,maxN);
  36.     }
  37.     return;
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement