好吧所以我试图让用户输入一个数字,然后将该数字分配给变量,这显然不会发生这种情况。我还希望它然后打印变量。请解释何时分配变量以及当我要求变量时数字的位置。
来自python,所以不知道还能做什么但是这样问一下
h=raw_input('please enter number')
print h
我想在C
中这样做#include <stdio.h>
int main()
{
int this_is_a_number;
printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );
printf( "You entered %d", this_is_a_number );
a=%d
printf(a)
return 0;
}
为什么这个不起作用我认为它解决了这些问题 #include
int main()
{
int this_is_a_number;
int a;
printf( "Please enter a number: /n" );
scanf( "%d", &this_is_a_number );
printf( "You entered %d", this_is_a_number );
a=this_is_a_number
printf("%d/n",&a)
return 0;
}
以下是最新代码的错误:
Building m.obj.
C:\Users\Admin\Google Drive\firstCShit\m.c(4): warning #2117: Old-style function definition for 'main'.
C:\Users\Admin\Google Drive\firstCShit\m.c(12): error #2001: Syntax error: expected ';' but found 'printf'.
C:\Users\Admin\Google Drive\firstCShit\m.c(14): warning #2234: Argument 2 to 'printf' does not match the format string; expected 'int' but found 'int *'.
C:\Users\Admin\Google Drive\firstCShit\m.c(14): error #2001: Syntax error: expected ';' but found 'return'.
*** Error code: 1 ***
Done.
答案 0 :(得分:2)
a
int this_is_a_number, a;
a = this_is_a_number;
答案 1 :(得分:1)
您的尝试逐行细分:
#include <stdio.h>
int main()
{
// Reserve the space in which to store the number
int this_is_a_number;
// Output a string, note no newline (\n) at the end of
// the string means this will probably not be printed
// before moving to the next statement
printf( "Please enter a number: " );
//read in an integer (%d) and store it at the address of the variable (this_is_a_number)
scanf( "%d", &this_is_a_number );
// Print the number entered, again no newline, but stdout should be flushed
printf( "You entered %d", this_is_a_number );
// This line is syntactically incorrect and makes no sense
a=%d
// This line is semantically incorrect, probably a type error
// printf requires a format string, like in the example two lines up
printf(a)
// Exit successfully
return 0;
}
要解决您的编辑问题,等效的C是:
#include <stdio.h>
int main()
{
int h;
printf("Please enter a number:\n");
scanf("%d", &h);
printf("%d\n", h);
return 0;
}