从标准输入中读取一个整数(在 C 中) [英] Read an integer from stdin (in C)
本文介绍了从标准输入中读取一个整数(在 C 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个 C 程序,将一个整数作为输入,并输出它的平方.这是我尝试过的.
I want to write a C program that takes as input an integer, and outputs its square. Here is what I have tried.
然而,
./a.out <3
输出 32768,并且./a.out <4
也输出 32768.
./a.out < 3
outputs 32768, and./a.out < 4
also outputs 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 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文