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();
}
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();
}
No comments:
Post a Comment