SlideShare uma empresa Scribd logo
1 de 5
Assignment

1. Display an hourglass pattern
2. #include <iostream>
3. #include <string>
4. #include <sstream>
5. #include <iomanip>
6.
7. using namespace std;
8.
9. const char star = '*';
10.
const char space = ' ';
11.
12.
int main(int argc, char *argv[]) {
13.
int n, m, i = 0, increment = 1;
14.
string in;
15.
stringstream ss;
16.
17.
do {
18.
cout << "Enter height (an odd, positive integer, > 2): ";
19.
getline(cin,in);
20.
ss.clear(); ss.str(in);
21.
} while (!(ss >> n) || (n < 3) || (!(n & 1)));
22.
23.
m = n / 2;
24.
25.
do {
26.
cout << setfill(space) << setw(i + 1) << space;
27.
cout << setfill(star) << setw(n - (2*i)) << star << endl;
28.
i += increment;
29.
if (i == m) increment = -1;
30.
} while (i >= 0);
31.
32.
system("pause");
33. }
Using hash ###

#include
#include
#include
#include

<iostream>
<string>
<sstream>
<iomanip>

using namespace std;
const char hash = '#';
const char space = ' ';
int main(int argc, char *argv[]) {
int n, m, i = 0, increment = 1;
string in;
stringstream ss;
do {
cout << "Enter height (an odd, positive integer, > 2): ";
getline(cin,in);
ss.clear(); ss.str(in);
} while (!(ss >> n) || (n < 3) || (!(n & 1)));
m = n / 2;
do {
cout << setfill(space) << setw(i + 1) << space;
cout << setfill(hash) << setw(n - (2*i)) << hash << endl;
i += increment;
if (i == m) increment = -1;
} while (i >= 0);
system("pause");
}
2. Display a diamond pattern
#include <iostream>
using namespace std;
void main()
{
int i, j, k;
int n = 0;
cout << "Program for displaying pattern of *.n";
cout << "Enter the maximum number of *: ";
cin >> n;
cout << "nHere is the Diamond of Starsn";
for (i = 1; i <= n; i++)
{
for (j = 0; j < (n - i); j++)
cout << " ";
for (j = 1; j <= i; j++)
cout << "*";
for (k = 1; k < i; k++)
cout << "*";
cout << "n";
}
for (i = n - 1; i >= 1; i--)
{
for (j = 0; j < (n - i); j++)
cout << " ";
for (j = 1; j <= i; j++)
cout << "*";
for (k = 1; k < i; k++)
cout << "*";
cout << "n";
}
cout << "n";
system("pause");
}
3. Display the Nepal flag
#include <iostream>
using namespace std;
void main()
{
int i, j, k;
int n = 0;
cout << "Program for displaying pattern of *.n";
cout << "Enter the maximum number of *: ";
cin >> n;
cout << "nHere is the Diamond of Starsn";
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
cout << "*";
cout << "n";
}
for (i = n - 1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
cout << "*";
cout << "n";
}
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
cout << "*";
cout << "n";
}
for (i = n - 1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
cout << "*";
cout << "n";
}
cout << "n";
system("pause");
}

Mais conteúdo relacionado

Mais procurados

Doubly linklist
Doubly linklistDoubly linklist
Doubly linklistilsamaryum
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語Kiyotaka Oku
 
Class array
Class arrayClass array
Class arraynky92
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловYandex
 
Zone.js 2017
Zone.js 2017Zone.js 2017
Zone.js 2017Jia Li
 
Patrick Kettner - JavaScript without javascript
Patrick Kettner - JavaScript without javascriptPatrick Kettner - JavaScript without javascript
Patrick Kettner - JavaScript without javascriptOdessaJS Conf
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"OdessaJS Conf
 
The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181Mahmoud Samir Fayed
 
Programa donde suma las filass de las dos columna y ordena el resultado de l...
Programa donde suma  las filass de las dos columna y ordena el resultado de l...Programa donde suma  las filass de las dos columna y ordena el resultado de l...
Programa donde suma las filass de las dos columna y ordena el resultado de l...Yo no soy perfecta pero soy mejor que tu
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScriptRaphael Cruzeiro
 
The Ring programming language version 1.5.3 book - Part 41 of 184
The Ring programming language version 1.5.3 book - Part 41 of 184The Ring programming language version 1.5.3 book - Part 41 of 184
The Ring programming language version 1.5.3 book - Part 41 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 45 of 88
The Ring programming language version 1.3 book - Part 45 of 88The Ring programming language version 1.3 book - Part 45 of 88
The Ring programming language version 1.3 book - Part 45 of 88Mahmoud Samir Fayed
 

Mais procurados (20)

Include
IncludeInclude
Include
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
NVT MD
NVT MDNVT MD
NVT MD
 
Multi qubit entanglement
Multi qubit entanglementMulti qubit entanglement
Multi qubit entanglement
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
 
Class array
Class arrayClass array
Class array
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
 
Zone.js 2017
Zone.js 2017Zone.js 2017
Zone.js 2017
 
Patrick Kettner - JavaScript without javascript
Patrick Kettner - JavaScript without javascriptPatrick Kettner - JavaScript without javascript
Patrick Kettner - JavaScript without javascript
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181
 
Programa donde suma las filass de las dos columna y ordena el resultado de l...
Programa donde suma  las filass de las dos columna y ordena el resultado de l...Programa donde suma  las filass de las dos columna y ordena el resultado de l...
Programa donde suma las filass de las dos columna y ordena el resultado de l...
 
Vcs23
Vcs23Vcs23
Vcs23
 
Single qubit-gates operations
Single qubit-gates operationsSingle qubit-gates operations
Single qubit-gates operations
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScript
 
MongoDB
MongoDBMongoDB
MongoDB
 
The Ring programming language version 1.5.3 book - Part 41 of 184
The Ring programming language version 1.5.3 book - Part 41 of 184The Ring programming language version 1.5.3 book - Part 41 of 184
The Ring programming language version 1.5.3 book - Part 41 of 184
 
The Ring programming language version 1.3 book - Part 45 of 88
The Ring programming language version 1.3 book - Part 45 of 88The Ring programming language version 1.3 book - Part 45 of 88
The Ring programming language version 1.3 book - Part 45 of 88
 
Caropro
CaroproCaropro
Caropro
 
Ee
EeEe
Ee
 

Destaque

Types Of Plannings
Types Of PlanningsTypes Of Plannings
Types Of PlanningsTahir Pasha
 
C programming project by navin thapa
C programming project by navin thapaC programming project by navin thapa
C programming project by navin thapaNavinthp
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...Brian Solis
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source CreativitySara Cannon
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 

Destaque (7)

Types Of Plannings
Types Of PlanningsTypes Of Plannings
Types Of Plannings
 
C programming project by navin thapa
C programming project by navin thapaC programming project by navin thapa
C programming project by navin thapa
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source Creativity
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Semelhante a Hourglass Pattern C++TITLE Diamond Pattern C++ TITLE Nepal Flag Pattern C

Semelhante a Hourglass Pattern C++TITLE Diamond Pattern C++ TITLE Nepal Flag Pattern C (20)

oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
C programs
C programsC programs
C programs
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
project3
project3project3
project3
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
C++ programming pattern
C++ programming patternC++ programming pattern
C++ programming pattern
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Rkf
RkfRkf
Rkf
 
Managing console
Managing consoleManaging console
Managing console
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Aa
AaAa
Aa
 
Arrays
ArraysArrays
Arrays
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 

Último

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Último (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Hourglass Pattern C++TITLE Diamond Pattern C++ TITLE Nepal Flag Pattern C

  • 1. Assignment 1. Display an hourglass pattern 2. #include <iostream> 3. #include <string> 4. #include <sstream> 5. #include <iomanip> 6. 7. using namespace std; 8. 9. const char star = '*'; 10. const char space = ' '; 11. 12. int main(int argc, char *argv[]) { 13. int n, m, i = 0, increment = 1; 14. string in; 15. stringstream ss; 16. 17. do { 18. cout << "Enter height (an odd, positive integer, > 2): "; 19. getline(cin,in); 20. ss.clear(); ss.str(in); 21. } while (!(ss >> n) || (n < 3) || (!(n & 1))); 22. 23. m = n / 2; 24. 25. do { 26. cout << setfill(space) << setw(i + 1) << space; 27. cout << setfill(star) << setw(n - (2*i)) << star << endl; 28. i += increment; 29. if (i == m) increment = -1; 30. } while (i >= 0); 31. 32. system("pause"); 33. }
  • 2. Using hash ### #include #include #include #include <iostream> <string> <sstream> <iomanip> using namespace std; const char hash = '#'; const char space = ' '; int main(int argc, char *argv[]) { int n, m, i = 0, increment = 1; string in; stringstream ss; do { cout << "Enter height (an odd, positive integer, > 2): "; getline(cin,in); ss.clear(); ss.str(in); } while (!(ss >> n) || (n < 3) || (!(n & 1))); m = n / 2; do { cout << setfill(space) << setw(i + 1) << space; cout << setfill(hash) << setw(n - (2*i)) << hash << endl; i += increment; if (i == m) increment = -1; } while (i >= 0); system("pause"); }
  • 3. 2. Display a diamond pattern #include <iostream> using namespace std; void main() { int i, j, k; int n = 0; cout << "Program for displaying pattern of *.n"; cout << "Enter the maximum number of *: "; cin >> n; cout << "nHere is the Diamond of Starsn"; for (i = 1; i <= n; i++) { for (j = 0; j < (n - i); j++) cout << " "; for (j = 1; j <= i; j++) cout << "*"; for (k = 1; k < i; k++) cout << "*"; cout << "n"; } for (i = n - 1; i >= 1; i--) { for (j = 0; j < (n - i); j++) cout << " "; for (j = 1; j <= i; j++) cout << "*"; for (k = 1; k < i; k++) cout << "*"; cout << "n"; } cout << "n"; system("pause"); }
  • 4. 3. Display the Nepal flag #include <iostream> using namespace std; void main() { int i, j, k; int n = 0; cout << "Program for displaying pattern of *.n"; cout << "Enter the maximum number of *: "; cin >> n; cout << "nHere is the Diamond of Starsn"; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) cout << "*"; cout << "n"; } for (i = n - 1; i >= 1; i--) { for (j = 1; j <= i; j++) cout << "*"; cout << "n"; } for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) cout << "*"; cout << "n"; } for (i = n - 1; i >= 1; i--) { for (j = 1; j <= i; j++) cout << "*"; cout << "n"; } cout << "n"; system("pause");
  • 5. }