Monday, 17 October 2016

HHW Q6. WAP to check whether a no. is prime or not .

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b=0,n;
cout<<"Enter the no. = ";
cin>>n;
for (int i=1;i<=n;i++)
{ a=n%i;
  if (a==0)
     { b++;
     }
}
if (b==2)
{ cout<<n<<" is a Prime no. ";
}
else
{ cout<<n<<" is not a prime no. ";
}
getch();
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...