20_10

Write a C program to determine whether a given number is prime or not.

 Source code:

//Write a C program to determine whether a given number (other than 1) is prime or not

#include <stdio.h>

int main(){


int num, flag=0; /*flag is used to take decision */ 

printf("Enter a number: ");

    scanf("%d",&num); 

int i;

for(i=2;i<=num/2;i++)

{

if(num%i==0)

    flag=1;

}

if(flag == 1)

        printf("NOT PRIME");

    else

        printf("PRIME");

    return 0;

}

Output:

Write a C program to determine whether a given number is prime or not


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...