jeudi 25 mars 2021

My program that I created to check whether a number is prime or not is not giving out any output

#include<stdio.h>

int main(){
    int i, n, prime=0;
    printf("Enter any positive integer:\n");
    scanf("%d", n);
    for(i=2; i<=n; i++){
        if(n%i==0){
            prime=1;
            break;
        }
    }
    if(n==1){
        printf("1 is neither prime not composite.");
    }
    else{
        if(prime==0){
            printf("%d is a prime number.", n);
        }
        else{
            printf("%d is not a prime number.", n);
         }
    }
    return 0;
}

I don't know what the problem here is but it never works. It only takes in the input but then after that just shows a blank line and then nothing happens. I also compared it with another code for the same problem online and it looked almost looked similar and I couldn't find the problem here.

Aucun commentaire:

Enregistrer un commentaire