-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Pranav-Jindal/patch-1
Create Pattern.cpp
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <iostream> | ||
// #include <string> | ||
#include<fstream> | ||
|
||
using namespace std; | ||
|
||
int pattern(int n){ | ||
int c; | ||
cout<<"Enter 0 if you want triangle\nEnter 1 if you want reverse triangle "; | ||
cin>>c; | ||
if (c==0) | ||
{ | ||
for (int i = 0; i < n; i++) | ||
{ | ||
for (int j = 0; j < i+1; j++) | ||
{ | ||
cout<<"*"; | ||
} | ||
cout<<"\n"; | ||
} | ||
} | ||
else if (c==1) | ||
{ | ||
for (int i = n; i > 0; i--) | ||
{ | ||
for (int j = i; j > 0; j--) | ||
{ | ||
cout<<"*"; | ||
} | ||
cout<<"\n"; | ||
} | ||
} | ||
else | ||
{ | ||
cout<<"Invalid Input"; | ||
return -1; | ||
} | ||
return 1; | ||
} | ||
|
||
int main(){ | ||
while (true) | ||
{ | ||
int no_of_lines; | ||
cout<<"Enter no of lines you want in pattern "; | ||
cin>>no_of_lines; | ||
if (no_of_lines>0) | ||
{ | ||
int result=pattern(no_of_lines); | ||
// if (result!=-1){ | ||
// break; | ||
// } | ||
} | ||
else | ||
{ | ||
cout<<"Invalid input"; | ||
} | ||
|
||
int Choice; | ||
cout<<"Continue printing another pattern?? -- Press any no\nExit Program -- 0 "; | ||
cin>>Choice; | ||
if (Choice==0){ | ||
cout<<"Thanks For Using Our Program!!!"<<endl; | ||
break; | ||
} | ||
} | ||
return 0; | ||
} |