-3
我想知道是否用户定义函数的格式,我写回车(x x x)是否正确。 因为当我编译我的代码时,我必须输入2次输入。 这可能是一个愚蠢的错误,因为我刚开始学习C语言 ****我的代码:****``简单C源代码中的错误?
#include<stdio.h>
long cube(long x);
long input,answer;
int main (void)
{
printf("Enter a number:");
scanf("%ld ",&input);
answer = cube(input);
printf(" The cube of %ld is %ld",input ,answer);
return 0;
}
long cube(long x)
{
return (x*x*x);
}
**** ****回答
#include <stdio.h>
long cube(long x);
long input, answer;
int main(void)
{
printf("Enter an integer value: ");
scanf("%d", &input);
answer = cube(input);
printf("\nThe cube of %ld is %ld.\n", input, answer);
return 0;
}
long cube(long x)
{
long x_cubed;
x_cubed = x * x * x;
return x_cubed;
}
邮报答案的答案(有一些解释)*我敢肯定,这是一个重复反正* – pmg
它真的不清楚你在这里问什么 – hardillb
提示:为什么你在''%ld“'中有一个空格?代码在数字后面寻找空格,所以'scanf()'没有完成,直到找到_all_白色空格出现在数字后 – chux