Monday, September 12, 2022

C Program for Prime Number

C Program For Prime Number

 //C Program for Prime Number

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n, m, i, c=0;

printf("Enter a Number\n");

scanf("%d",&n);

m=n/2;

for(i=2;i<=m;i++)

{

if(n%i==0)

{

printf("%d is not a prime number",n);

c++;

break;

}

}

if(c==0)

{

printf("%d is a Primne number",n);

}

getch();

}

YouTube Video

(Please Subscribe our Channel)


C Program to check whether inputed number is a Prime Number or not by using for loop without using mid value...

//C Program to check wether inputed number //is a prime or not #include<stdio.h> #include<conio.h> void main() { clrscr(); int n, c=0, i; printf("Enter a number\n"); scanf("%d",&n); for(i=1;i<=n;i++) { if(n%i==0) c++; } if(c==2) printf("%d is a prime number",n); else printf("%d is not a prime number",n); getch(); }

YouTube Video

(Please Subscribe our Channel)



No comments:

Post a Comment