P. 1
Write a Program That Will Find the Highest Common Factor ,Prime Number and Maximum Devisor.

Write a Program That Will Find the Highest Common Factor ,Prime Number and Maximum Devisor.

|Views: 515|Likes:

See more
See less

10/19/2012

pdf

text

original

Write a program that will find the highest common factor ,prime number

and maximum devisor.
i.e. press 1 for HFC
press 2 for Prime Number
press 3 for greatest common devisor
============================================
#include<iostream.h>
#include<conio.h>
void main()
{
int a=0;
while(a!=3)
{
cout<<"[1] for maths\n";
cout<<"[2] for diagrams\n";
cout<<"[3] for Exit\n";
cin>>a;
if(a==1)
{
while(a!=4)
{
cout<<"[1] for Greates common Devisor\n";
cout<<"[2] for check prime number\n";
cout<<"[3] for maximum devisor \n";
cout<<"[4] for go to main menu\n";
cin>>a;
if(a==1)
{
cout<<"\t\t GREATEST COMMON
DEVISOR\n";
int a,b,c,d,gcd=0;
cout<<"Enter three integers";
cin>>a>>b>>c;
if(a>=b && a>=c)
d=a;
else if(b>=a && b>=c)
d=b;
else if(c>=a && c>=b)
d=c;
for(int i=1; i<=d; i++)
if((a%i)==0 && (b%i)==0 &&
(c%i)==0)
gcd=i;
cout<<"GCD is "<<gcd<<"\n\n\n";
cout<<"press any key to return menu\n";
getche();
}
if(a==2)
{
cout<<"\t\t PRIME NUMBER\n";
int a,flag=0;
cout<<"Enter any number";
cin>>a;
for(int i=2; i<a; i++)
{
if((a%i)==0)
{
flag=1;
break;
}
}
if(flag==0)
cout<<"Number is prime\n\n\n\n";
else
cout<<"Number is not
Prime\n\n\n";
cout<<"press any key to return menu\n";
getche();
}
if(a==3)
{
cout<<"\t\t MAXIMUM DEVISOR\n";
int a,b,rem;
cout<<"Enter two values";
cin>>a>>b;
if(a>b)
{
rem=a%b;
a-=rem;
a/=b;
cout<<"\n"<<a;
}
cout<<"press any key to return menu\n";
getche();
}
}
}
if(a==2)
{
while(a!=3)
{
cout<<"[1] for box\n";
cout<<"[2] for diamond\n";
cout<<"[3] for go to main menu\n";
cin>>a;
if(a==1)
{
cout<<"\t\t BOX\n";
int width,height;
cout<<"Enter width and height";
cin>>width>>height;
for(int i=0; i<width; i++)
cout<<"*";
cout<<endl;
for(i=0; i<height-2;i++)
{
cout<<"*";
for(int j=0; j<width-2;j++)
cout<<" ";
cout<<"*";
cout<<endl;
}
for(i=0; i<width; i++)
cout<<"*";
cout<<"\n\n\n\n";
cout<<"press any key to return menu\n";
getche();
}
if(a==2)
{
cout<<"\t\t DIAMOND\n";
int a;
cin>>a;
a/=2;
for(int i=0;i<a;i++)
cout<<" ";
cout<<"*\n";
for(int line=1; line<a; line++)
{
for(int space=a; space>line; space--
)
{
cout<<" ";
}
cout<<"*";
for(int counter=0;
counter<(line+line-1); counter++)
{
cout<<" ";
}
cout<<"*";
cout<<endl;
}
for(int line1=a; line1>0; line1--)
{
for(int space1=a; space1>line1;
space1--)
{
cout<<" ";
}
cout<<"*";
for(int counter1=0;
counter1<(line1+line1-1);
counter1++)
{
cout<<" ";
}
cout<<"*";
cout<<endl;
}
for(i=0;i<a;i++)
cout<<" ";
cout<<"*\n";
cout<<"press any key to return menu\n";
getche();
}
if(a==3)
{
a=0;
break;
}
}
}
}
}
http://www.ravianeducation.blogspot.com
FARHAN: 03008855006

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->