Problem E: 零起点学算法34——3n+1问题
#include<stdio.h>
#include<math.h>
int main()
{
int n;
n<=pow(,);
int count=;
scanf("%d",&n);
while(n!=)
{
count++;
if(n%==)
n=n/;
else
n=n*+;
}
printf("%d\n",count);
return ;
}
HINT
使用 while 循环使用 while 语句在条件成立时重复某动作,类似于 if 语句,只要条件为 true 就重复动作。 while 循环计算一个表达式的值,如果表达式为 true,则会执行循环体中的代码。如果条件计算结果为 true,在循环返回以再次计算条件前执行一条语句或一系列语句。条件计算结果为 false 后,则跳过语句或一系列语句并结束循环。在不确定要将一个代码块循环多少次时,使用 while 循环可能会非常有用。 例如,下面的代码将数字显示到"输出"面板中: var i:Number = 0; while (i < 5) { trace(i); i++; } 您会看到以下数字显示到"输出"面板中: 0 1 2 3 4 使用 while 循环而非 for 循环的一个缺点是,在 while 循环中更有可能编写出无限循环。如果遗漏递增计数器变量的表达式,则 for 循环示例代码将无法编译;而 while 循环示例代码将能够编译。若没有递增 i 的表达式,循环将成为无限循环。
Problem E: 零起点学算法34——3n+1问题的更多相关文章
- Problem J: 零起点学算法34——3n+1问题
#include<stdio.h> int main() { ; int n; scanf("%d",&n); ) { ==) n=n*+; else n/=; ...
- 1129: 零起点学算法36——3n+1问题
1129: 零起点学算法36--3n+1问题 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 4541 ...
- 武汉科技大学ACM:1004: 零起点学算法36——3n+1问题
Problem Description 任给一个正整数n,如果n为偶数,就将它变为n/2,如果为奇数,则将它乘3加1(即3n+1).不断重复这样的运算,经过有限步后,一定可以得到1 . Input 输 ...
- 武汉科技大学ACM :1001: 零起点学算法34——继续求多项式
Problem Description 输入1个正整数n, 计算1+(1+2)+(1+2+3)+...+(1+2+3+...+n) Input 输入正整数n(多组数据) Output 输出1+(1+2 ...
- Problem H: 零起点学算法109——单数变复数
#include <stdio.h> #include<string.h> int main(void) { int n; ]; scanf("%d",&a ...
- Problem G: 零起点学算法106——首字母变大写
#include<stdio.h> #include<string.h> int main(void) { ]; int i,k; while(gets(a)!=NULL) { ...
- Problem D: 零起点学算法95——弓型矩阵
#include<stdio.h> #include<string.h> int main() { ][]; while(scanf("%d%d",& ...
- Problem F: 零起点学算法42——多组测试数据输出II
#include<stdio.h> int main() { ; while(scanf("%d%d%d",&a,&b,&c)!=EOF) { ...
- Problem K: 零起点学算法107——统计元音
#include<stdio.h> int main() { int n; ]; while(scanf("%d%*c",&n)!=EOF) { while(n ...
随机推荐
- make command explaination 編譯命令解釋
Creating .config file make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32_defconfig 以上命令是 將變數 ARCH=arm, ...
- python基础===字符串的制表,换行基础操作
\n\t 制表符和换行符 >>> print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Pyth ...
- 阿波罗11号登月飞船电脑控制系统源码(AGC)
阿波罗11号登月飞船电脑控制系统源码(AGC) http://download.csdn.net/detail/downiis6/9574926 down url: https://github.co ...
- python 判断文件的创建时间和当前时间的比较
import os import time import datetime filePath=r"C:\pyweibo\cookies5673210223" ctime=os.pa ...
- BZOJ 3771 生成函数,FFT
Description 我们讲一个悲伤的故事. 从前有一个贫穷的樵夫在河边砍柴. 这时候河里出现了一个水神,夺过了他的斧头,说: “这把斧头,是不是你的?” 樵夫一看:“是啊是啊!” 水神把斧头扔在一 ...
- 无缝滚动Js
<html> <body> <div style="width: 190px; height: 127px; overflow: hidden; font-si ...
- windows下使用github
1.首先到github.com注册用户: 2.下载git,地址:http://pan.baidu.com/s/1skPpWlB(64位下载):http://pan.baidu.com/s/1skOAa ...
- POJ 2492 A Bug's Life(带权并查集)
题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...
- 在Redis集群中使用pipeline批量插入
在Redis集群中使用pipeline批量插入 由于项目中需要使用批量插入功能, 所以在网上查找到了Redis 批量插入可以使用pipeline来高效的插入, 示例代码如下: Pipeline p = ...
- hdu 3572(构图+最大流)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...