簡體   English   中英

為什么第一個 C 代碼導致一個變量和 3 個變量中的第二個。 有沒有辦法通過輕微的改變使第一個程序工作?

[英]Why does the 1st C code result in one variable and the 2nd in 3 variables. Is there a way to make the first program work by slight changes?

誰能幫助理解為什么我的結果是 20100 而第二個結果是 3 個值,因為它應該幫助我完成未來的項目? 我是編程和 C 的新手。

我的版本

#include <stdio.h>

int main (void)
{   
    int toes
    toes = 10;
    
    int x,y;
    
    x= toes * 2;
    printf ("%d", x);
    y= toes * toes;
    printf ("%d", y);
}

正確的版本:

#include <stdio.h>

int main(void)
{
    int toes;
    toes = 10;
    printf("toes = %d\n", toes);
    
    printf("Twice toes = %d\n", 2 * toes);
    printf("toes squared = %d\n", toes * toes);
    
    return 0;
}

你的計算是對的。 您唯一缺少的是分隔20100的換行符:

x= toes * 2;
printf ("%d\n", x);
/* Here----^ */
y= toes * toes;
printf ("%d\n", y);
/* And Here^ */

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM