1.(1)if...else 用法

#include <iostream>

#include <cstring>

using namespace std;

int main()

{

char X;

cout<<"Menu:A(dd) D(elete) S(ort) Q(uit),Select one:"<<endl;

while(cin>>X){

if(X=='A')

cout<<"Data has been added"<<endl;

else if(X=='D')

cout<<"Data has been deleted"<<endl;

else if(X=='S')

cout<<"Data has been sorted"<<endl;

else if(X=='Q')

break;

else

cout<<"Data does not exist"<<endl;

}

return 0;

}

(2)switch 用法

#include <iostream>

using namespace std;

int main()

{

char X;

cout<<"Menu:A(dd) D(elete) S(ort) Q(uit),Select one:"<<endl;

while(cin>>X){

if(X=='Q')

break;

switch(X){

case 'A': cout<<"Data has been added"<<endl;

break;

case 'D': cout<<"Data has been deleted"<<endl;

break;

case 'S': cout<<"Data has been sorted"<<endl;

break;

default: cout<<"Data does not exist"<<endl;

break;

}

}

return 0;

}

2.(1)for 用法

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int i,j,k;

for(i=2;i<=100;i++)

{

k=sqrt((double)i);

for(j=2;j<=k;j++)

{

if(i%j==0)

break;

}

if(j>k)

cout<<i <<" ";

}

return 0;

}

(2)while 用法

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int i=2,j,k;

while(i<=100)

{

k=sqrt((double)i);

for(j=2;j<=k;j++)

{

if(i%j==0)

break;

}

if(j>k)

cout<<i <<" ";

i++;

}

return 0;

}

(3)do...while 用法

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int i=2,j,k;

do

{

k=sqrt((double)i);

for(j=2;j<=k;j++)

{

if(i%j==0)

break;

}

if(j>k)

cout<<i <<" ";

i++;

}while(i<=100);

return 0;

}

3.(1)while 用法

#include<iostream>

using namespace std;

int main()

{

int i=23,j;

cout<<"Guess the num between 1 and 100:"<<endl;

while(cin>>j)

{

if(j>i&&j<=100)

cout<<"bigger than the num"<<endl;

else if(j>=1&&j<i)

cout<<"lower than the num"<<endl;

else if(j==i)

cout<<"Congratulations! You're right."<<endl;

else

cout<<"Error"<<endl;

}

return 0;

}

(2)do...while 用法

#include<iostream>

using namespace std;

int main()

{

int i=23,j;

cout<<"Guess the num between 1 and 100:"<<endl;

do

{

if(j>i&&j<=100)

cout<<"bigger than the num"<<endl;

else if(j>=1&&j<i)

cout<<"lower than the num"<<endl;

else if(j==i)

cout<<"Congratulations! You're right."<<endl;

else

cout<<"Error"<<endl;

}while(cin>>j);

return 0;

}

4.

#include<iostream>

using namespace std;

int main()

{

cout<<"the ways to go together is ";

int i,sum=1;

for(i=5;i>=3;i--)

{

sum*=i;

}

for(i=3;i>=1;i--)

{

sum/=i;

}

cout <<sum;

return 0;

}

最新文章

  1. iOS开发 iOS10推送必看(基础篇)
  2. Spark算上下基线
  3. 2015弱校联盟(1) - I. Travel
  4. Centos6.7下安装配置VPN
  5. Linux用户组管理
  6. RDLC系列之六 打印纸张的大小(未解决)
  7. innodb_io_capacity &gt;=innodb_lru_scan_depth*inoodb_buffer_pool_instances。与 checkpoint
  8. linux文件权限解说
  9. C++ Primer 学习笔记_75_模板与泛型编程 --模板定义
  10. ASP.NET - URL中参数加密解密操作
  11. CSS滚动条样式定制
  12. ORACLE 多表关联 UPDATE 语句
  13. 最小化spring XML配置,Spring提供了4种自动装配策略。
  14. 利用Python中SocketServer 实现客户端与服务器间非阻塞通信
  15. LeetCode解题录-51~100
  16. tp5中代替tp3.2中的一些方法
  17. go语言之进阶篇runtime包中 Gosched Goexit GOMAXPROCS的使用
  18. 对话框(VC_Win32)
  19. oralce 存储过程、函数和触发器
  20. Javascript中的继承与Prototype

热门文章

  1. vue-cli新版 -- 记录
  2. js-分享功能插件
  3. Sleep和wait
  4. 批量执行 sql 的 shell 脚本
  5. TCP常见的定时器及三次握手与四次挥手
  6. javascript/jquery获取url地址栏参数的方法
  7. [原创]创芯电子实验室iFPGA-Cable JTAG工具实物图
  8. 使用 RAII 完成线程等待
  9. ReactiveCocoa - study
  10. 关闭 Visual Studio 的 Browser Link 功能