SlideShare a Scribd company logo
1 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
Task 3:
//numbers.cpp
C++ program: ordering numbers:
even, odd & prime
(desending-ascending) order
Prepared By:
Khalid Waleed
CANAL HIGH INSTITUTE OF ENGINEERING & TECHNOLOGY
2 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
1: // numbers.cpp
2: // program for ordering numbers: even,odd & prime
3: #include <iostream>
4: usingnamespace std;
5: void error(int&);
6: int main()
7: {
8: int process , numb , f=0;
9: char ask;
10: do{
11: cout <<" 1- ordering even numbers n 2- ordering odd numbers
12: n 3- ordering prime numbers";
13: cout <<"ninsert number of process : ";
14: cin >> process;
15: error(process);
16: switch(process)
17: {
18: case1:
19: cout <<"n 4- desending order n 5- ascending order ";
20: cout <<"ninsert number of process : ";
21: cin >> process;
22: error(process);
23: switch(process)
24: {
25: case4:
26: cout <<"Enter your number : ";
27: cin >> numb;
28: error(numb);
29: for(numb ; numb>0;--numb)
30: {
3 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
31: if(numb%2==0)
32: {
33: cout << numb <<", ";
34: }
35: }
36: break;
37: case5:
38: cout <<"Enter your number : ";
39: cin >> numb;
40: error(numb);
41: for(int c=1; numb>=c ; c++)
42: {
43: if(c%2==0)
44: {
45: cout << c <<", ";
46: }
47: }
48: break;
49: default:
50: cout <<"number of process unknown !";
51: }
52: break;
53: case2:
54: cout <<"n 6- desending order n 7- ascending order ";
55: cout <<"ninsert number of process : ";
56: cin >> process;
57: error(process);
58: switch(process)
59: {
60: case6:
61: cout <<"Enter your number : ";
4 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
62: cin >> numb;
63: error(numb);
64: for(numb ; numb>0;--numb)
65: {
66: if(numb%2!=0)
67: {
68: cout << numb <<", ";
69: }
70: }
71: break;
72: case7:
73: cout <<"Enter your number : ";
74: cin >> numb;
75: error(numb);
76: for(int c=1; numb>=c ; c++)
77: {
78: if(c%2!=0)
79: {
80: cout << c <<", ";
81: }
82: }
83: break;
84: default:
85: cout <<"number of process unknown !";
86: }
87: break;
88: case3:
89: cout <<"n 8- desending order n 9- ascending order ";
90: cout <<"ninsert number of process : ";
91: cin >> process;
92: error(process);
5 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
93: switch(process)
94: {
95: case8:
96: cout <<"Enter your number : ";
97: cin >> numb;
98: error(numb);
99: for(numb ; numb>=2;--numb)
100: {
101: f=0;
102: for(int j=2; j<=numb/2; j++)
103: {
104: if(numb%j ==0)
105: {
106: f=1;
107: break;
108: }
109: }
110: if(f==0)
111: cout << numb <<", ";
112: }
113: break;
114: case9:
115: cout <<"Enter your number : ";
116: cin >> numb;
117: error(numb);
118: for(int c=2; numb>=c ; c++)
119: {
120: f=0;
121: for(int j=2; j<=c/2; j++)
122: {
123: if(c % j ==0)
6 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
124: {
125: f=1;
126: break;
127: }
128: }
129: if(f==0)
130: cout << c <<", ";
131: }
132: break;
133: default:
134: cout <<"number of process unknown !"; 135:
136: }
137: break;
138: default:
139: cout <<"number of process unknown !";
140: }
141: cout <<"ndo another (y/n) ? ";
142: cin >> ask;
143: }while(ask == 'y');
144: return0;
145: }
146: void error(int&x)
147: {
148: while(cin.fail())
149: {
150: cin.clear();// clear input buffer to restore cin to a usable state
151: cin.ignore(INT_MAX, 'n');// ignore last input
152: cout <<"You can only enter numbers.n";
153: cout <<"Enter a number : ";
154: cin >> x;
155: }
7 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y
156: }

More Related Content

What's hot

Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
mohdshanu
 
Palindrome number program c
Palindrome number program cPalindrome number program c
Palindrome number program c
mohdshanu
 
Prime number program in c
Prime number program in cPrime number program in c
Prime number program in c
Hitesh Kumar
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramidnayakq
 
C workshop day 6
C workshop day 6C workshop day 6
C workshop day 6
Mayank Agrawal
 
VLSI Sequential Circuits II
VLSI Sequential Circuits IIVLSI Sequential Circuits II
VLSI Sequential Circuits IIGouthaman V
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programmeShah Keval
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4
Aman Kamboj
 
2 d rotation
2 d rotation2 d rotation
2 d rotation
Chandu Kumare
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
Dr. Loganathan R
 
Palindrome number program in c
Palindrome number program in cPalindrome number program in c
Palindrome number program in c
mohdshanu
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
Bharat Kalia
 
C & Python Introduction
C & Python IntroductionC & Python Introduction
C & Python Introduction
Spy Seat
 

What's hot (20)

Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
 
week-11x
week-11xweek-11x
week-11x
 
Palindrome number program c
Palindrome number program cPalindrome number program c
Palindrome number program c
 
Prime number program in c
Prime number program in cPrime number program in c
Prime number program in c
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
 
C workshop day 6
C workshop day 6C workshop day 6
C workshop day 6
 
VLSI Sequential Circuits II
VLSI Sequential Circuits IIVLSI Sequential Circuits II
VLSI Sequential Circuits II
 
บทที่ 3
บทที่ 3บทที่ 3
บทที่ 3
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4
 
2 d rotation
2 d rotation2 d rotation
2 d rotation
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
Lab loop
Lab loopLab loop
Lab loop
 
Ppt Prog Fox
Ppt Prog FoxPpt Prog Fox
Ppt Prog Fox
 
Ppt Prog Fox
Ppt Prog FoxPpt Prog Fox
Ppt Prog Fox
 
week-4x
week-4xweek-4x
week-4x
 
Palindrome number program in c
Palindrome number program in cPalindrome number program in c
Palindrome number program in c
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
C & Python Introduction
C & Python IntroductionC & Python Introduction
C & Python Introduction
 

Similar to C++ program: Numbers .cpp

C++ program: All tasks .cpp
C++ program: All tasks .cppC++ program: All tasks .cpp
C++ program: All tasks .cpp
Khalid Waleed
 
C++ program: Day calculation .cpp
C++ program: Day calculation .cppC++ program: Day calculation .cpp
C++ program: Day calculation .cpp
Khalid Waleed
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
Doug Hawkins
 
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAMPROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
C Programming
C ProgrammingC Programming
C Programming
Sumant Diwakar
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C lab
C labC lab
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdfAssignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
SamiulHaque58
 
C++ file
C++ fileC++ file
Cpp programs
Cpp programsCpp programs
Cpp programs
harman kaur
 
20DCE096_dlp_prac5.pdf
20DCE096_dlp_prac5.pdf20DCE096_dlp_prac5.pdf
20DCE096_dlp_prac5.pdf
ShivangPithadiya1
 
Vhdl programs
Vhdl programsVhdl programs
Vhdl programs
Kirthika Natarajan
 
Reporte vhd10
Reporte vhd10Reporte vhd10
Reporte vhd10
Miguel Angel Peña
 

Similar to C++ program: Numbers .cpp (20)

C++ program: All tasks .cpp
C++ program: All tasks .cppC++ program: All tasks .cpp
C++ program: All tasks .cpp
 
C++ program: Day calculation .cpp
C++ program: Day calculation .cppC++ program: Day calculation .cpp
C++ program: Day calculation .cpp
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAMPROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
 
C Programming
C ProgrammingC Programming
C Programming
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
C lab
C labC lab
C lab
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Ch4
Ch4Ch4
Ch4
 
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdfAssignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
 
C++ file
C++ fileC++ file
C++ file
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
20DCE096_dlp_prac5.pdf
20DCE096_dlp_prac5.pdf20DCE096_dlp_prac5.pdf
20DCE096_dlp_prac5.pdf
 
Vhdl programs
Vhdl programsVhdl programs
Vhdl programs
 
Progr3
Progr3Progr3
Progr3
 
Reporte vhd10
Reporte vhd10Reporte vhd10
Reporte vhd10
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 

Recently uploaded

English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 

Recently uploaded (20)

English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 

C++ program: Numbers .cpp

  • 1. 1 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y Task 3: //numbers.cpp C++ program: ordering numbers: even, odd & prime (desending-ascending) order Prepared By: Khalid Waleed CANAL HIGH INSTITUTE OF ENGINEERING & TECHNOLOGY
  • 2. 2 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 1: // numbers.cpp 2: // program for ordering numbers: even,odd & prime 3: #include <iostream> 4: usingnamespace std; 5: void error(int&); 6: int main() 7: { 8: int process , numb , f=0; 9: char ask; 10: do{ 11: cout <<" 1- ordering even numbers n 2- ordering odd numbers 12: n 3- ordering prime numbers"; 13: cout <<"ninsert number of process : "; 14: cin >> process; 15: error(process); 16: switch(process) 17: { 18: case1: 19: cout <<"n 4- desending order n 5- ascending order "; 20: cout <<"ninsert number of process : "; 21: cin >> process; 22: error(process); 23: switch(process) 24: { 25: case4: 26: cout <<"Enter your number : "; 27: cin >> numb; 28: error(numb); 29: for(numb ; numb>0;--numb) 30: {
  • 3. 3 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 31: if(numb%2==0) 32: { 33: cout << numb <<", "; 34: } 35: } 36: break; 37: case5: 38: cout <<"Enter your number : "; 39: cin >> numb; 40: error(numb); 41: for(int c=1; numb>=c ; c++) 42: { 43: if(c%2==0) 44: { 45: cout << c <<", "; 46: } 47: } 48: break; 49: default: 50: cout <<"number of process unknown !"; 51: } 52: break; 53: case2: 54: cout <<"n 6- desending order n 7- ascending order "; 55: cout <<"ninsert number of process : "; 56: cin >> process; 57: error(process); 58: switch(process) 59: { 60: case6: 61: cout <<"Enter your number : ";
  • 4. 4 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 62: cin >> numb; 63: error(numb); 64: for(numb ; numb>0;--numb) 65: { 66: if(numb%2!=0) 67: { 68: cout << numb <<", "; 69: } 70: } 71: break; 72: case7: 73: cout <<"Enter your number : "; 74: cin >> numb; 75: error(numb); 76: for(int c=1; numb>=c ; c++) 77: { 78: if(c%2!=0) 79: { 80: cout << c <<", "; 81: } 82: } 83: break; 84: default: 85: cout <<"number of process unknown !"; 86: } 87: break; 88: case3: 89: cout <<"n 8- desending order n 9- ascending order "; 90: cout <<"ninsert number of process : "; 91: cin >> process; 92: error(process);
  • 5. 5 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 93: switch(process) 94: { 95: case8: 96: cout <<"Enter your number : "; 97: cin >> numb; 98: error(numb); 99: for(numb ; numb>=2;--numb) 100: { 101: f=0; 102: for(int j=2; j<=numb/2; j++) 103: { 104: if(numb%j ==0) 105: { 106: f=1; 107: break; 108: } 109: } 110: if(f==0) 111: cout << numb <<", "; 112: } 113: break; 114: case9: 115: cout <<"Enter your number : "; 116: cin >> numb; 117: error(numb); 118: for(int c=2; numb>=c ; c++) 119: { 120: f=0; 121: for(int j=2; j<=c/2; j++) 122: { 123: if(c % j ==0)
  • 6. 6 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 124: { 125: f=1; 126: break; 127: } 128: } 129: if(f==0) 130: cout << c <<", "; 131: } 132: break; 133: default: 134: cout <<"number of process unknown !"; 135: 136: } 137: break; 138: default: 139: cout <<"number of process unknown !"; 140: } 141: cout <<"ndo another (y/n) ? "; 142: cin >> ask; 143: }while(ask == 'y'); 144: return0; 145: } 146: void error(int&x) 147: { 148: while(cin.fail()) 149: { 150: cin.clear();// clear input buffer to restore cin to a usable state 151: cin.ignore(INT_MAX, 'n');// ignore last input 152: cout <<"You can only enter numbers.n"; 153: cout <<"Enter a number : "; 154: cin >> x; 155: }
  • 7. 7 | P a g e C A N A L H I G H E R I N S T I T U T E O F E N G I N E E R I N G & T E C H N O L O G Y 156: }