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


相关文章
|
9月前
|
XML Java 数据格式
详尽分享第二章:微服务与SpringCloudEureka上篇
详尽分享第二章:微服务与SpringCloudEureka上篇
25 0
|
10月前
|
Java
【Java开发指南 | 第十一篇】Java运算符
【Java开发指南 | 第十一篇】Java运算符
33 2
|
10月前
|
存储 SpringCloudAlibaba Java
手把手教你,从零开始搭建Spring Cloud Alibaba!这份笔记太牛了
Spring Cloud Alibaba 是阿里巴巴提供的微服务开发一站式解决方案,是阿里巴巴开源中间件与 Spring Cloud 体系的融合。
|
并行计算 安全 Java
2023年Java核心技术第十一篇(篇篇万字精讲)
2023年Java核心技术第十一篇(篇篇万字精讲)
72 2
|
Java 数据库连接 数据库
spring高级源码笔记:深入理解阿里spring源码核心思想及框架应用
Spring 是分层的 full-stack(全栈) 轻量级开源框架,以 IoC 和 AOP 为内核,提供了展现层 SpringMVC 和业务层事务管理等众多的企业级应⽤技术,还能整合开源世界众多著名的第三⽅框架和类库,已经成为使⽤最多的 Java EE 企业应⽤开源框架。
257 0
|
移动开发 JavaScript 前端开发
面试题练习第五篇
面试题练习第五篇
120 1
|
前端开发 C# 数据库管理
(3) MasaFramework 入门第三篇,使用MasaFramework
(3) MasaFramework 入门第三篇,使用MasaFramework
132 0
(3) MasaFramework 入门第三篇,使用MasaFramework
|
缓存 监控 Java
膜拜!Alibaba最新发布SprinBoot:进阶原理实战与面试题分析指南
本书对Spring Boot的各项功能特性及其最佳实践、实现原理展开讨论,涵盖了核心容器、Web服务、内置缓存、数据访问、并发编程、监控和扩展等一系列核心主题,这些核心主题也广泛应用于Spring家族中的其他开发框架。
157 0