C Program Diary

Tuesday, October 16, 2012

Program to check a prime number.


Some Basic C program frequently asked in Interview.

/* Program to check whether a number is prime or not*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a number:\t");
scanf("%d",&a);
b=2;
while(a%b!=0)
{
b++;
}
if(a==b)
{
printf("\n%d is prime number",a);
}
else printf("\n\t%d is not prime number",a);
getch();
}

Posted by Abc at 11:58 AM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: c

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ▼  2012 (17)
    • ▼  October (17)
      • Copy Constructor & this pointer
      • Operator Overloading Program
      • Default Arguments Program
      • Program To Find Sum Of Digit
      • Program To Convert a Number into Binary
      • Program to check a prime number.
      • Program to Calculate power of a number
      • Program To check a Number is Pallindrome & Armstrong
      • C program to replace multiple spaces with a single...
      • Count number of words in a string
      • Frequently asked C programs
      • Binary Search Tree
      • Stack implementation using C++
      • Insertion Sort algorithm in C++
      • Linked List Implementation using C++
      • Merge Sort program in c in a simple way:
      • Simple Linked List Program to add a node

About Me

Abc
View my complete profile
Awesome Inc. theme. Powered by Blogger.