SlideShare a Scribd company logo
1 of 3
Write C++ program that when given a value N(read from cin), produces a pictogram of the first
N^2 numbers, as follows: for each number, print what is stated below.
Thank you so much!
Solution
#include <iostream>
using namespace std;
int factors[20];
void findFactors(int n)
{
//cout << "Factors of " << n << " are: " << endl;
int j=0;
for(int i=1;i<=n;++i)
{
if(n%i==0)
{
//cout << i << endl;
factors[j]=i;
j=j+1;
}
}
factors[j]=-1;
}
int isPrime(int no)
{
int i, flag=0;
for(i=2;i<=no/2;++i)
{
if(no%i==0)
{
flag=1;
break;
}
}
if (flag==1)
return 1;
else
return 0;
}
int main()
{
int n,i;
cout << "Enter a positive integer: ";
cin >> n;
for(int j=1;j<=(n*n);j++)
{
if(j%n==0)
cout<<endl;
if(isPrime(j)==1)
{
cout<<"P";
}
else
{ int count=0;
findFactors(j);
int k=0;
while(factors[k]!=-1)
{
if(isPrime(factors[k])==1)
count=count+1;
k=k+1;
}
if(count>=2)
cout<<'2';
else
cout<<'.';
}
}
return 0;
}
C++ program pictogram first N squared numbers

More Related Content

Similar to C++ program pictogram first N squared numbers

Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in CSaket Pathak
 
Assignment c++12
Assignment c++12Assignment c++12
Assignment c++12Syed Umair
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdfT17Rockstar
 
Workshop03.docx lap trinh C cho người mới bắt đầu
Workshop03.docx  lap trinh C cho người mới bắt đầuWorkshop03.docx  lap trinh C cho người mới bắt đầu
Workshop03.docx lap trinh C cho người mới bắt đầulinhtran111111111111
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
PYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfPYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfNeeraj381934
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxShamshad
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxtristans3
 

Similar to C++ program pictogram first N squared numbers (20)

C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
Program presentation
Program presentationProgram presentation
Program presentation
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Assignment c++12
Assignment c++12Assignment c++12
Assignment c++12
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdf
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
Workshop03.docx lap trinh C cho người mới bắt đầu
Workshop03.docx  lap trinh C cho người mới bắt đầuWorkshop03.docx  lap trinh C cho người mới bắt đầu
Workshop03.docx lap trinh C cho người mới bắt đầu
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
pattern-printing-in-c.pdf
pattern-printing-in-c.pdfpattern-printing-in-c.pdf
pattern-printing-in-c.pdf
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
C programs
C programsC programs
C programs
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
PYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfPYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdf
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docx
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 

More from karlynwih

Zone Diameter Interpretation Examine the zone diameter data in the tab.docx
Zone Diameter Interpretation Examine the zone diameter data in the tab.docxZone Diameter Interpretation Examine the zone diameter data in the tab.docx
Zone Diameter Interpretation Examine the zone diameter data in the tab.docxkarlynwih
 
Your unknown bacteria maybe one of the following 13 bacteria- Proteus.docx
Your unknown bacteria maybe one of the following 13 bacteria- Proteus.docxYour unknown bacteria maybe one of the following 13 bacteria- Proteus.docx
Your unknown bacteria maybe one of the following 13 bacteria- Proteus.docxkarlynwih
 
Your friend got a notification on their iPhone letting them know they.docx
Your friend got a notification on their iPhone letting them know they.docxYour friend got a notification on their iPhone letting them know they.docx
Your friend got a notification on their iPhone letting them know they.docxkarlynwih
 
Your reflection must be at least 400 words Examine habitat for humanit.docx
Your reflection must be at least 400 words Examine habitat for humanit.docxYour reflection must be at least 400 words Examine habitat for humanit.docx
Your reflection must be at least 400 words Examine habitat for humanit.docxkarlynwih
 
You will learn about the Chain of Infection and apply your learning to.docx
You will learn about the Chain of Infection and apply your learning to.docxYou will learn about the Chain of Infection and apply your learning to.docx
You will learn about the Chain of Infection and apply your learning to.docxkarlynwih
 
Write definitions for the following terms- hydrograph- hyetograph- abs.docx
Write definitions for the following terms- hydrograph- hyetograph- abs.docxWrite definitions for the following terms- hydrograph- hyetograph- abs.docx
Write definitions for the following terms- hydrograph- hyetograph- abs.docxkarlynwih
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxkarlynwih
 
Write an SML function groupdupes that takes a list of integers as its.docx
Write an SML function groupdupes that takes a list of integers as its.docxWrite an SML function groupdupes that takes a list of integers as its.docx
Write an SML function groupdupes that takes a list of integers as its.docxkarlynwih
 
You and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docxYou and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docxkarlynwih
 
Write an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docxWrite an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docxkarlynwih
 
Write an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxWrite an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxkarlynwih
 
write a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docxwrite a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docxkarlynwih
 
Write up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docxWrite up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docxkarlynwih
 
Write an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docxWrite an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docxkarlynwih
 
Write the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docxWrite the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docxkarlynwih
 
Write the formal description of the following state machine (M) What.docx
Write the formal description of the following state machine (M)  What.docxWrite the formal description of the following state machine (M)  What.docx
Write the formal description of the following state machine (M) What.docxkarlynwih
 
Write the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docxWrite the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docxkarlynwih
 
Write the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docxWrite the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docxkarlynwih
 
Write functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docxWrite functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docxkarlynwih
 
Write about the two sources of energy Write about the two sources of.docx
Write about the two sources of energy   Write about the two sources of.docxWrite about the two sources of energy   Write about the two sources of.docx
Write about the two sources of energy Write about the two sources of.docxkarlynwih
 

More from karlynwih (20)

Zone Diameter Interpretation Examine the zone diameter data in the tab.docx
Zone Diameter Interpretation Examine the zone diameter data in the tab.docxZone Diameter Interpretation Examine the zone diameter data in the tab.docx
Zone Diameter Interpretation Examine the zone diameter data in the tab.docx
 
Your unknown bacteria maybe one of the following 13 bacteria- Proteus.docx
Your unknown bacteria maybe one of the following 13 bacteria- Proteus.docxYour unknown bacteria maybe one of the following 13 bacteria- Proteus.docx
Your unknown bacteria maybe one of the following 13 bacteria- Proteus.docx
 
Your friend got a notification on their iPhone letting them know they.docx
Your friend got a notification on their iPhone letting them know they.docxYour friend got a notification on their iPhone letting them know they.docx
Your friend got a notification on their iPhone letting them know they.docx
 
Your reflection must be at least 400 words Examine habitat for humanit.docx
Your reflection must be at least 400 words Examine habitat for humanit.docxYour reflection must be at least 400 words Examine habitat for humanit.docx
Your reflection must be at least 400 words Examine habitat for humanit.docx
 
You will learn about the Chain of Infection and apply your learning to.docx
You will learn about the Chain of Infection and apply your learning to.docxYou will learn about the Chain of Infection and apply your learning to.docx
You will learn about the Chain of Infection and apply your learning to.docx
 
Write definitions for the following terms- hydrograph- hyetograph- abs.docx
Write definitions for the following terms- hydrograph- hyetograph- abs.docxWrite definitions for the following terms- hydrograph- hyetograph- abs.docx
Write definitions for the following terms- hydrograph- hyetograph- abs.docx
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docx
 
Write an SML function groupdupes that takes a list of integers as its.docx
Write an SML function groupdupes that takes a list of integers as its.docxWrite an SML function groupdupes that takes a list of integers as its.docx
Write an SML function groupdupes that takes a list of integers as its.docx
 
You and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docxYou and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docx
 
Write an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docxWrite an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docx
 
Write an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxWrite an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docx
 
write a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docxwrite a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docx
 
Write up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docxWrite up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docx
 
Write an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docxWrite an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docx
 
Write the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docxWrite the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docx
 
Write the formal description of the following state machine (M) What.docx
Write the formal description of the following state machine (M)  What.docxWrite the formal description of the following state machine (M)  What.docx
Write the formal description of the following state machine (M) What.docx
 
Write the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docxWrite the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docx
 
Write the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docxWrite the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docx
 
Write functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docxWrite functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docx
 
Write about the two sources of energy Write about the two sources of.docx
Write about the two sources of energy   Write about the two sources of.docxWrite about the two sources of energy   Write about the two sources of.docx
Write about the two sources of energy Write about the two sources of.docx
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 

C++ program pictogram first N squared numbers

  • 1. Write C++ program that when given a value N(read from cin), produces a pictogram of the first N^2 numbers, as follows: for each number, print what is stated below. Thank you so much! Solution #include <iostream> using namespace std; int factors[20]; void findFactors(int n) { //cout << "Factors of " << n << " are: " << endl; int j=0; for(int i=1;i<=n;++i) { if(n%i==0) { //cout << i << endl; factors[j]=i; j=j+1; } } factors[j]=-1; } int isPrime(int no) { int i, flag=0; for(i=2;i<=no/2;++i) { if(no%i==0) { flag=1;
  • 2. break; } } if (flag==1) return 1; else return 0; } int main() { int n,i; cout << "Enter a positive integer: "; cin >> n; for(int j=1;j<=(n*n);j++) { if(j%n==0) cout<<endl; if(isPrime(j)==1) { cout<<"P"; } else { int count=0; findFactors(j); int k=0; while(factors[k]!=-1) { if(isPrime(factors[k])==1) count=count+1; k=k+1; } if(count>=2) cout<<'2'; else cout<<'.'; } } return 0; }