gpt4 book ai didi

c - 从标准输入中读取一个整数(在 C 中)

转载 作者:太空宇宙 更新时间:2023-11-04 05:51:40 25 4
gpt4 key购买 nike

我想编写一个 C 程序,将一个整数作为输入,并输出它的平方。这是我试过的。

但是,

  • ./a.out < 3输出 32768,和
  • ./a.out < 4也输出 32768。

我哪里错了?谢谢。

#include <stdio.h>

int main(){
int myInt;
scanf("%d", &myInt);
printf("%d\n",myInt*myInt);
}

最佳答案

看起来你想做的是

echo 4 | ./a.out

<的语法是

program < input_file

鉴于 |是

command_with_output | program

关于c - 从标准输入中读取一个整数(在 C 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39936299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com