Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

prime number in c

#include<stdio.h>
void main(){
    int num, i;
    int cp = 1;
    printf("Enter a number = ");
    scanf("%d",&num);

    if(num > 0){
        for(i = 2; i < num; i++){
            if(num % i == 0){
                cp = 0;
            }
        }
        if(cp == 1){
            printf("%d is a prime number.", num);
        }
        else{
            printf("%d isn't a prime number.", num);
        }
    }
}
Source by www.w3schools.in #
 
PREVIOUS NEXT
Tagged: #prime #number
ADD COMMENT
Topic
Name
7+5 =