명령 프롬프트가 다소 이상하게 작동합니다.

명령 프롬프트가 다소 이상하게 작동합니다.

내 C 프로그램이 명령과 같이 상대적으로 간단한 경우 printf명령 프롬프트는 출력을 훌륭하게 제공합니다.

암호:

#include <stdio.h>
int main(){printf("Get out!");}

산출:

C:\Users\amish>gcc whatever.c
C:\Users\amish>a
Get out!

그러나 코드가 다음과 같은 경우:

#include <stdio.h>
  int is_composite(int a){
    int i;
    int b = 0;
     if(a == 1){b = 2;};
    for(i=2; i<a;i++){
     
    if(a%i ==0){b = 1;
    break;
    };
    
     
   
  }
   return b;}
  int main(){
    int n1;
    int n2;
    int k;
    int l;
    printf("ENTER TWO NUMBERS");
    scanf("%d", &n1);
    scanf("%d", &n2);

    for(k = n1; k<=n2; k++){
      l = is_composite(k);
      if(l == 0){printf("%d ", k);}
    }
   
    return 0 ;}

산출:

C:\Users\amish>gcc whatever.c
C:\Users\amish>a
Access is denied.

왜 간단한 코드에서는 작동하지만 복잡한 코드에서는 작동하지 않는지 정말 이해가 되지 않습니다. 아니면 전혀 다른 이유가 있습니까? 어떤 도움이라도 주시면 감사하겠습니다!

관련 정보