SlideShare a Scribd company logo
1 of 7
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

Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
nayakq
 
VLSI Sequential Circuits II
VLSI Sequential Circuits IIVLSI Sequential Circuits II
VLSI Sequential Circuits II
Gouthaman V
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
Shah Keval
 

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

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
 

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

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 

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: }