SlideShare ist ein Scribd-Unternehmen logo
1 von 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");
}

Weitere Àhnliche Inhalte

Was ist angesagt?

Doubly linklist
Doubly linklistDoubly linklist
Doubly linklistilsamaryum
 
Multi qubit entanglement
Multi qubit entanglementMulti qubit entanglement
Multi qubit entanglementVijayananda Mohire
 
ăšă‚ă‚‹æ–­ç‰‡ăźè¶…ć‹•çš„èš€èȘž
ăšă‚ă‚‹æ–­ç‰‡ăźè¶…ć‹•çš„èš€èȘžăšă‚ă‚‹æ–­ç‰‡ăźè¶…ć‹•çš„èš€èȘž
ăšă‚ă‚‹æ–­ç‰‡ăźè¶…ć‹•çš„èš€èȘž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
 
Single qubit-gates operations
Single qubit-gates operationsSingle qubit-gates operations
Single qubit-gates operationsVijayananda Mohire
 
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
 
Caropro
CaroproCaropro
Caroprodaquicaro
 

Was ist angesagt? (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
 

Andere mochten auch

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Ăž
 

Andere mochten auch (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
 

Ähnlich wie C programs

C programs
C programsC programs
C programsAzaj Khan
 
C++ practical
C++ practicalC++ practical
C++ practicalRahul juneja
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1kkkseld
 
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.pdfshreeaadithyaacellso
 
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 commandsVishvjeet Yadav
 
C++ programming pattern
C++ programming patternC++ programming pattern
C++ programming patternRaushankumar550
 
Managing console
Managing consoleManaging console
Managing consoleShiva Saxena
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical fileMitul Patel
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9Dr. Md. Shohel Sayeed
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignmentJunaid Ahmed
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic typesmohamed sikander
 

Ähnlich wie C programs (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
 

KĂŒrzlich hochgeladen

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

KĂŒrzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

C programs

  • 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. }