问题描述:

In the following simple program after the user inputs an integer the command line remains a flashing prompt. When I exit the program the answer is then printed out. Why is this and how can I fix it?

//powers of 2

#include <stdio.h>

int main(void){

int a,b=1,i;

printf("What power of 2?\n");

scanf("%i\n",&a);

for (i=0; i<a;i++)

{

b=b*2;

}

printf("the answer is: %i\n",b);

return 0;

}

网友答案:

Try remove the \n in your scan :

 scanf("%i",&a);
网友答案:

Remove \n from scanf. After that I compiled your program and it worked properly.

相关阅读:
Top