c++第五篇

简介: c++第五篇
#include<bits/stdc++.h>
using namespace std;
int main()
{
  //while
  int num = 0;
  while (num < 10)
  {
    cout << "num = " << num << endl;
    num++;
  }
  //猜数字
  //rand()%100随机生成1-99的整数
  int ans=rand()%100+1;
  int val;
  while(1){
    cin>>val;
    if(val>ans){
      cout<<"大了"<<endl;
    }
    else if(val<ans){
      cout<<"小了"<<endl;
    }
    else{
      cout<<"猜对了"<<endl;
      break;
    }
  } 
  //do...while
  int num1 = 0;
  do
  {
    cout << num1 << endl;
    num1++;
  } while (num1 < 10);
  //水仙花数
  int test=100;
  while(test<=999)
  {
    int a,b,c;
    a=test%10;
    b=test/10%10;
    c=test/100;
      int d=a*a*a+b*b*b+c*c*c;
    if(d==test)
    {
      cout<<d<<endl;
    }
    test++;
  }
  //for 循环
  for (int i = 0; i < 10; i++)
  {
    cout << i << endl;
  }
  //敲桌子
  for(int i=1;i<=100;i++)
  {
    if(i%7==0||i%10==7||i/10==7){
      cout<<i<<"敲桌子"<<endl;
    }
   } 
   //嵌套循环
  for (int i = 0; i < 10; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      cout << "*" << " ";
    }
    cout << endl;
  } 
   //九九乘法表
  for(int i=1;i<=9;i++)
  {
    for(int j=1;j<=i;j++)
    {
      cout<<j<<" "<<"*"<<" "<<i<<" = "<<j*i<<" ";
    }
    cout<<endl;
  }
  //break语句  一般用于switch和循环(嵌套循环)
  //continue语句
  for (int i = 0; i < 100; i++)
  {
    if (i % 2 == 0)
    {
      continue;
    }
    cout << i << endl;
  } 
  //goto语句(比较少用)
  cout << "1" << endl;
  goto FLAG;
  cout << "2" << endl;
  cout << "3" << endl;
  cout << "4" << endl;
  FLAG:
  cout << "5" << endl; 
  return 0;
}


相关文章
|
4月前
|
安全 架构师 Java
理论实战源码齐飞!架构师社区疯传的SpringSecurity进阶小册真香
安全管理是Java应用开发中无法避免的问题,随着Spring Boot和微服务的流行,Spring Security受到越来越多Java开发者的重视,究其原因,还是沾了微服务的光。作为Spring家族中的一员,其在和Spring家族中的其他产品如SpringBoot、Spring Cloud等进行整合时,是拥有众多同类型框架无可比拟的优势的。
55 0
|
8月前
|
存储 算法 安全
2023年Java核心技术第十篇(篇篇万字精讲)
2023年Java核心技术第十篇(篇篇万字精讲)
65 0
|
8月前
|
缓存 安全 Java
2023年Java核心技术第九篇(篇篇万字精讲)(上)
2023年Java核心技术第九篇(篇篇万字精讲)(上)
35 0
|
8月前
|
存储 安全 Java
2023年Java核心技术第九篇(篇篇万字精讲)(下)
2023年Java核心技术第九篇(篇篇万字精讲)(下)
41 0
|
8月前
|
并行计算 安全 Java
2023年Java核心技术第十一篇(篇篇万字精讲)
2023年Java核心技术第十一篇(篇篇万字精讲)
38 2
|
9月前
|
移动开发 JavaScript 前端开发
面试题练习第五篇
面试题练习第五篇
60 1
|
10月前
|
前端开发 C# 数据库管理
(3) MasaFramework 入门第三篇,使用MasaFramework
(3) MasaFramework 入门第三篇,使用MasaFramework
66 0
(3) MasaFramework 入门第三篇,使用MasaFramework
|
12月前
|
C++
c++第四篇
c++第四篇
|
12月前
|
C++
c++第七篇
c++第七篇
|
12月前
|
C++
c++第六篇
c++第六篇

热门文章

最新文章