当前位置:网站首页>使用C语言实现Hailstone序列
使用C语言实现Hailstone序列
2022-08-08 06:20:00 【开门大弟子】
Hailstone的数学部分不做讲解,程序如下,我把Hailstione程序写为3部分,main.cpp、function.cpp、Hailstone.h.各部分如下:
main.cpp
#include "Hailstone.h"
int main()
{
Hail();
return 0;
}
function.cpp
#include "Hailstone.h"
void Hail()
{
int N;
cout << "输入数值:" << endl;
cin >> N;
int result = Hailstone(N);
cout << "length =" << result << endl;
}
int Hailstone(int n)
{
int length = 1;
while(1 < n)
{
(n % 2 != 0) ? (n = 3 * n + 1) : (n = n / 2);
cout << "n = " << n << endl;
length++;
}
return length;
}
Hailstone.h
#include <stdlib.h>
#include <iostream>
using namespace std;
int Hailstone(int n);
void Hail();
边栏推荐
- 图解LeetCode——636. 函数的独占时间(难度:中等)
- Basic tools - NETCAT (Telnet - banner, transfer text message)
- navicat15 连接Oracle数据库 报错ORA-28547: connection to server failed, probable Oracle Net admin error的解决方案
- 基于knn的手写数字识别
- Key technologies for 4G/5G spectrum resource coordination
- MySQL5
- automation tool
- 仿记事本;QFile
- 人体神经元细胞分布图片,神经元人体分布大图
- 最完整的分布式架构设计图谱
猜你喜欢

数字IC设计笔试题汇总(四):一些基础知识点

MySQL6

卷积神经网络 图像识别,卷积神经网络 图像处理

MySQL database

【RPC】Mercury RPC

教你六步拆解 DDD领域驱动设计落地实践

Completed - desktop interactive wizard design based on facial expressions (share the results, attach the data set of facial expressions and the yolov5 model trained by yourself and the interactive int

KDD'22 Recommendation System Papers (24 Research & 36 Application Papers)

uniapp H5 签名横版生成图片

Redis 的内存策略
随机推荐
Tensorboard的使用 ---- SummaryWriter类(pytorch版)
2021 mathematical modeling national competition question B
Docker安装nacos2.0并指定mysql,安装sentinel
postgis 数据表 迁移时错误解决方法
开发两年,作为过来人的建议
Query and track multiple express tracking numbers, and filter the tracking numbers shipped at a certain time
navicat15 连接Oracle数据库 报错ORA-28547: connection to server failed, probable Oracle Net admin error的解决方案
Maykle Studio - Deep Learning - BP Neural Network
李沐老师 PyTorch版——线性回归 + softmax回归的简洁实现(3)
nacos的配置中心
automation tool
命令提示符adb shell的具体配置和使用方法
Redis In Action —— Advanced —— 数据主从同步原理 —— 全量同步 与 增量同步 工作流程及原理 —— 以及如何利用 docker 容器技术快速模拟单机 Redis 集群
Unity mouse cursor usage learning
Pit Filling Simulated Hash Table
LLVM系列第二十九章:写一个简单的常量加法“消除”工具(Pass)
Disadvantages of flex layout
日常bug小结:
docker安装Mysql和其数据持久化
Redis 的内存策略