#include<iostream.h> #include<conio.h> #include<stdio.h> class cplus { int i,j,n; public: void prime(); void even_odd(); void polin(); }; void cplus::prime() { int count; cout<<"enter n:"; cin>>n; for(j=2;j<=n;j++) { count=0; for(i=1;i<=j;i++) { if(j%i==0) count++; } if(count==2) cout<<j<<"\t"; } } void cplus::even_odd() { cout<<"enter n:"; cin>>n; cout<<"\neven nos:"; for(i=1;i<=n;i++) { if(i%2==0) cout<<"\t"<<i; } cout<<"\nodd nos:"; for(i=1;i<=n;i++) { if(i%2!=0) cout<<"\t"<<i; } } void cplus::polin() { int a,b=0; cout<<"enter n:"; cin>>n; a=n; while(a>0) { b=b*10+a%10; a=a/10; } if(b==n) cout<<"\n"<<n<<"is a polindrom"; else cout<<"\n"<<n<<"not a polindrom"; } void main() { clrscr(); cplus k; int ch; do { cout.fill('*'); cout.width(80); cout<<"\ncontrol structures"<<endl; cout.width(80); cout<<"\n1.prime\n2.even-odd\n3.polindrom"; cout<<"\nenter your choice:"; cin>>ch; switch(ch) { case 1: k.prime(); break; case 2: k.even_odd(); break; case 3: k.polin(); break; case 4: cout<<"exit"; } }while(ch!=4); }
Sunday, 7 December 2014
program to check given number is prime or not, even or odd, polindrome or not
Posted by Madan
Posted on 13:35