Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        4年前关闭。
                                                                                            
                
        
我在Ubuntu 14.04上键入此代码

#include<stdio.h>
int main() {

  int i, j, n;
  scanf("%",&n);
  for (i=0;i<=n;i++){
    for (j=0;j<=i;j++){
        printf("*");
    }
    printf("\n");
  }
  return 0;
}


但是它打印的星星过多,并且一直持续到我关闭它为止。

最佳答案

应该:

#include<stdio.h>
int main() {

int i, j, n;
scanf("%d",&n);
for (i=0;i<=n;i++){
    for (j=0;j<=i;j++){
        printf("*");
    }
    printf("\n");
}
return 0;
}


您忘记使用%d参数告诉scanf您正在读取整数

关于c - 打印过多的星星,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33598638/

10-13 05:55