Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void printPattern(int n,int maxN);
- int main()
- {
- int n;
- printf("Enter the Number of asterisks: ");
- scanf("%d",&n);
- if(n < 1)
- {
- printf("error! the number of lines can\'t be negative");
- return 1;
- }
- int numberOfLines = 2*n-1;
- printPattern(numberOfLines,n);
- return 0;
- }
- void printPattern(int n,int maxN)
- {
- if (n >= maxN)
- {
- for(int i = n ; i < 2*maxN; i++ )
- {
- printf("*");
- }
- printf("\n");
- printPattern(n-1,maxN);
- }
- else if(n >= 1)
- {
- for(int i = n;i >=1 ; i--)
- {
- printf("*");
- }
- printf("\n");
- printPattern(n-1,maxN);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement