Code ที่เขียนไว้ครับ มันยังมีเพี้ยนๆ อยู่ครับ ลิ้งค์ Flow ครับ >>
http://upic.me/i/uw/vecter.png <<
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
const int Numb = 7;
int i;
int a[7];
int mn,mx;
for(int i=0;i<7;i++)
{
cout << "Enter 7 numbers into the vector : ";
cin >> a
;
}
char choice;
cout << "\n######################## M E N U ########################";
cout << "\n A. Find the maximum number in the vector";
cout << "\n B. Find the minimum number in the vector";
cout << "\n C. Find the total of numbers in the vector";
cout << "\n D. Find all prime numbers in the vector";
cout << "\n Q. Quit Program";
cout << "\n Enter your choice : ";
cin >> choice;
switch(choice)
{
case 'A' :
case 'a' :
{
if (a > mx)
mx=a;
cout << " The maximum number in the vector is ... " << mx << endl;
return main();
}
break;
case 'B' :
case 'b' :
{
if(a < mx )
mn=a;
cout << " The minimum number in the vector is ... " << mn << endl;
return main();
}
break;
case 'C' :
case 'c' :
{cout<<"\n The total of numbers in the vector is\n";
}
break;
case 'D' :
case 'd' :
{cout<<"\n All prime numbers in the vector : \n";
}
break;
case 'Q' :
case 'q' :
{cout<<"\n Quit Program\n";
system("pause");
return 0;
}
break;
// other than <A, B, C or Q>...
default : cout<<"\n Invalid Choice";
// no break in the default case
}
cout<<"\n===============================================";
return main();
}
ช่วยดู code C++ vector การหาค่า max min sum แล้วก็ prime หน่อยครับ
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
const int Numb = 7;
int i;
int a[7];
int mn,mx;
for(int i=0;i<7;i++)
{
cout << "Enter 7 numbers into the vector : ";
cin >> a;
}
char choice;
cout << "\n######################## M E N U ########################";
cout << "\n A. Find the maximum number in the vector";
cout << "\n B. Find the minimum number in the vector";
cout << "\n C. Find the total of numbers in the vector";
cout << "\n D. Find all prime numbers in the vector";
cout << "\n Q. Quit Program";
cout << "\n Enter your choice : ";
cin >> choice;
switch(choice)
{
case 'A' :
case 'a' :
{
if (a > mx)
mx=a;
cout << " The maximum number in the vector is ... " << mx << endl;
return main();
}
break;
case 'B' :
case 'b' :
{
if(a < mx )
mn=a;
cout << " The minimum number in the vector is ... " << mn << endl;
return main();
}
break;
case 'C' :
case 'c' :
{cout<<"\n The total of numbers in the vector is\n";
}
break;
case 'D' :
case 'd' :
{cout<<"\n All prime numbers in the vector : \n";
}
break;
case 'Q' :
case 'q' :
{cout<<"\n Quit Program\n";
system("pause");
return 0;
}
break;
// other than <A, B, C or Q>...
default : cout<<"\n Invalid Choice";
// no break in the default case
}
cout<<"\n===============================================";
return main();
}