WIZARD401 2020-07-09 01:56 采纳率: 100%
浏览 267
已采纳

C语言 卡拉兹猜想代码 应该怎么改?

最近刚接触C语言,这是我写关于卡拉兹猜想的代码,在运行过程中碰到以下两个问题:

1.[Error] expected constructor, destructor, or type conversion before '(' token

2.cpp [Error] expected unqualified-id before 'while'

请问我这是哪里错了,应该怎么改

int x;
scanf("%d", &x);
int count=0;
while ( x > 1 )
{
    if x % 2 == 0
    {
        x = x / 2;
        count = count + 1;
    }
    else
    {
        x = (3*x + 1) / 2;
        count=count+1
    }
}
printf("%d",&count) 

在运行的时候,显示有两个错误:

1.[Error] expected constructor, destructor, or type conversion before '(' token

2.cpp [Error] expected unqualified-id before 'while'

  • 写回答

1条回答 默认 最新

  • 指针的值是地址 2020-07-09 09:02
    关注
    int main() {
        int x;
        scanf("%d", &x);
        int count = 0;
        while (x > 1)
        {
            if (x % 2 == 0)
            {
                x = x / 2;
                count = count + 1;
            }
            else
            {
                x = (3 * x + 1) / 2;
                count = count + 1;
            }
        }
        printf("%d", count);
        return 0;
    }
    

    C语言一句话的结尾要使用英文分号。
    if判断要加括号。
    printf使用错误。不需要&

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用