• 大小: 2.82KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-02-21
  • 标签:

资源简介

C++实战源码-角谷猜想(入门级实例074).zip

资源截图

代码片段和文件信息

// Guess.cpp : Defines the entry point for the console application.
//

#include “stdafx.h“
#include “stdio.h“

int main()
{
    long n; //定义变量为长整形
    printf(“请输入一个整数:\n“);
    scanf(“%ld“ &n); //从键盘中任意输入一长整形数
    while (n != 1) //当最终结果不为1时一直执行循环体语句
    {
        if (n % 2 == 0) //判断n是否为偶数
        {
            printf(“%ld/2=%ld\n“ n n / 2);
            n = n / 2; //当n为偶数时n除以2
        }
        else
        {
            printf(“%ld*3+1=%ld\n“ n n *3+1);
            n = n * 3+1; //当n为奇数时乘以3加1
        }
    }
  return 0;
}



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         682  2010-10-20 13:58  Guess\Guess.cpp
     文件        4524  2010-10-20 13:58  Guess\Guess.dsp
     文件         535  2010-10-20 13:58  Guess\Guess.dsw
     文件         292  2010-10-20 13:58  Guess\StdAfx.cpp
     文件         769  2010-10-20 13:58  Guess\StdAfx.h

评论

共有 条评论