To find prime numbers through C language

3,367 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,367
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

To find prime numbers through C language

  1. 1. C PROGRAMME TO IDENTIFYWHETHER A NUMBER IS PRIME OR COMPOSITE BY-SAURABH KHETAN
  2. 2.  The prime numbers are those numbers which are divisible by themselves and unity. We will implement this theory while constructing a program to find whether a number is prime or composite in C language. The main logic behind finding whether a number is prime number or not, we need to keep on dividing the number with number occurring before it. The program can be written as follows:-
  3. 3. #include<stdio.h>int main(){ int num, i=2; printf(“enter a number”); scanf(“%d”,&num); while(i<=num-1){ if(num%i==0) { printf(“the entered number is composite”); break; } else i++;}
  4. 4. if(i==num) { printf(“the entered number is a prime number”); }}
  5. 5.  The following program can be made to run in any of the compilers. For example:- Turbo c, Microsoft visual studio. Only for the compilers supported by windows operating system. This is a simplest program to identify whether a number is prime or composite. The user just have to enter the desired number and the result is displayed. Can be used to make school children comfortable with concept of the prime numbers.
  6. 6.  For any more details about this program you can enquire by sending me an e-mail. saurabh.khetan53@gmail.com Any query regarding it will be solved as soon as possible. Do mention your problem in detail while sending me an e-mail.

×