c++例题演示大一上学期课程设计(斐波那契数列,完数,素数)-创新互联
#include
#include
#include
#include
#include
using namespace std;
void _0621s1();
void _0621s2();
void _0621s3();
void _0621s5();
void _0621s6();
void _0621s7();
int i, j, k, c;
int main()
{
system("title 0621zhangsan");
system("mode con cols=76 lines=35"); //窗口宽度高度
system("date /T");
system("TIME /T");
system("VER");//显示windows版本
system("color E4");
_0621s1();
return 0;
}
void _0621s1()//主界面
{
cout<< "\t★★★★★\t\t\t\t\t★★★★★\n";
cout<< "\t★\t★\t\t\t\t\t★\t★\n";
cout<< "\t★\t★\t\t\t\t\t★\t★\n";
cout<< "\t★\t★\t\t\t\t\t★\t★\n";
cout<< "\t★\t★\t\t\t\t\t★\t★\n";
cout<< "\t★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t******************************************\t★\n";
cout<< "\t★\t**\t 欢迎使用变形菜单系统\t\t**\t★\n";
cout<< "\t★\t**\t\t\t\t\t**\t★\n";
cout<< "\t★\t**——————例题演示系统———————**\t★\n";
cout<< "\t★\t******************************************\t★\n";
cout<< "★★★★★★★\t\t\t\t\t\t ★★★★★★★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "★★★★★★★\t\t\t\t\t\t ★★★★★★★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "★★★★★★★-------------机器猫现在就带你研究-------------★★★★★★★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★\t\t-----版权所有,侵权必究-----\t\t★\n";
cout<< "\t★\t\t\t\t\t\t\t★\n";
cout<< "\t★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\n";
cout<< "进入系统请输入密码(您共有三次机会),退出系统请按0号键\n";
_0621s2();
}
void _0621s2()//密码
{
long p = 123456;
long p1;
int n = 3;
char c;
while (true)
{
cin >>p1;
if (p1 == p)
{
cout<< "密码正确,请按任意键继续"<< endl;
c = getch();
system("cls");
_0621s3();
break;
}
else
{
--n;
cout<< "密码错误,请重新输入,你还有"<< n<< "次机会"<< endl;
}
if (n == 0)
{
system("cls"); //清屏功能
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t |\_/| \n";
cout<< "\t | *x* | \n";
cout<< "\t \_____/ |\n";
cout<< "\t | | \n";
cout<< "\t \ ノ \n";
cout<< "\t ((( (/ ̄ ̄ ̄ ̄(/ ヽ) \n";
cout<< "您三次机会已用完,欢迎您的使用!ByeBye!....................";
}
}
}
void _0621s3()
{
while (true)
{
char b;
system("cls");
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t本系统提供的相关例题演示程序如下:\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t0.退出系统\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t3.输出斐波那契数列:\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t4.输出n内的所有素数:\n";
cout<< "\t\t\t\t\n";
cout<< "\t\t\t5.输出n内的所有完数:\n";
cout<< "请输入功能序号<0-4>:"<< endl;
cin >>b;
switch (b)
{
case '0':return;
case '3':_0621s5(); break;
case '4':_0621s6(); break;
case '5':_0621s7(); break;
}
}
}
void _0621s5()//斐波那契数列
{
int f1 = 0, f2 = 1, t, n = 1, p;
cout<< "请输入n:";
cin >>p;
cout<< "数列第1个:"<< f1<< endl;
cout<< "数列第2个:"<< f2<< endl;
for (n = 3; n<= p; n++) {
t = f2;
f2 = f1 + f2;
f1 = t;
cout<< "数列第"<< n<< "个:"<< f2<< endl;
}
cout<< endl;
cout<< "按下任意键返回选择菜单"<< endl;
c = getch();
}
void _0621s6()//完数
{
cout<< "请输入n:";
int n;
cin >>n;
for (int i = 2; i< n; ++i)
{
int k;
for (k = 2; k< n; ++k)
if (i % k == 0)break;
if (k == i)
cout<< i<< " ";
}
cout<< endl;
cout<< "按下任意键返回选择菜单"<< endl;
c = getch();
}
void _0621s7()//
{
int i, n, sum;
int a = 1, b;
cout<< "请输入n:";
cin >>b;
for (n = a; n<= b; n++)
{
sum = 0;
for (i = 1; i< n; i++)
{
if (n % i == 0)
{
sum = sum + i;
}
}
if (sum == n)
{
cout<< n<< endl;
}
}
cout<< endl;
cout<< "按下任意键返回选择菜单"<< endl;
c = getch();
}
密码:123456
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网页名称:c++例题演示大一上学期课程设计(斐波那契数列,完数,素数)-创新互联
文章位置:http://hbruida.cn/article/dogooe.html