program of prime number in c | C Programming by TechWithCode

Program of Prime Number in C:

Hello and Welcome to www.TechWithCode.com

Today we will learn about how to write a C Program to check whether a number is prime or not.

As We Know that A Prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers can't be divided by other numbers than itself or 1. For example 2, 3, 5, 7, 11, 13, 17, 19, 23.... are the prime numbers.


Actually, we have to implement the above definition of prime number in c programming.

So let's see the program of prime number in c. In this C program, we will take input from the user and check that whether this number is Prime or not.

Problem Statement⤵️


Write a C program that takes a number as input and check whether this number is Prime or Not.


Source Code⤵️

//Summary: Check whether a number is prime or not[ www.TechWithCode.com ]

#include <stdio.h> 
int main() {
	int n, i, flag=0;

	printf("Enter a positive integer: ");
	scanf("%d",&n); 

	for(i=2;i<=n/2;++i) { 
		if(n%i==0) { 
			flag=1; break; 
		} 
	} 

	if (flag==0)
		printf("\n\n%d is a prime number.\n\n",n);
	else 
		printf("\n\n%d is not a prime number.\n\n",n);
	return 0;
}


The output of program of prime number⤵️

program of prime number in c | C Programming by TechWithCode

1 comment:

  1. The most enduring symbol of the Norse - titanium arts
    › tj-metal-arts › tj-metal-arts The most gri-go.com enduring symbol of the goyangfc.com Norse - titanium arts · The most titanium metal trim enduring symbol of the Norse - titanium arts https://febcasino.com/review/merit-casino/ · The most enduring symbol of the 1xbet korean Norse - titanium arts.

    ReplyDelete

Do not add any link in the comments.
For backlink, contact us.

Powered by Blogger.