I want to know if the format of user defined function i wrote i.e return(xxx) is correct or not . Because when i compile my code, i have to enter the input 2 times.It might be a silly mistake because i just began learning C language ****MY CODE:****``
#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);
}
****ANswer****
#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;
}
答案 0 :(得分:0)
删除&#39;%ld&#39;之后的空格它需要一个输入。 根据你的代码, scanf(&#34;%ld&#39;&amp; input); 这里的编译器首先要为&#39;%ld&#39;然后它等待你在'%ld&#39;之后使用的空格。删除它然后它将在一次输入后进入下一步。 你应该用, 的scanf(&#34;%LD%&#34;,&安培;输入);