only for presentation purposes
Here are the Mumbai University First Year Engineering sem-2 Computer programing 2 (CP-2) programs.These are tried and tested and work just fine.Njoy!
Please refer this to all your pals on all your social networks..thank you !
The grey color is only for the background it should cause no problems.
-----------------------------------------------------------------------------------------------------------
/* Program of finding out the Greatest Common Division (GCD) or the Highest Common Factor (HCF) of the given two numbers, using while loop*/
import java.io.*;
class GCD
{
public static void main(String args[]) throws IOException
{
DataInputStream buf = new DataInputStream(System.in);
int n1,n2;
System.out.println("Enter 2nums");
n1=Integer.parseInt(buf.readLine());
n2=Integer.parseInt(buf.readLine());
System.out.print("The GCD of "+n1+" and "+n2);
while ((n1!=0) && (n2!=0))
{
if (n1 > n2)
n1 = n1 - n2 ;
else
n2 = n2 - n1 ;
}
System.out.print(" is "+n1);
try
{
System.out.println(" LCM is "+n1/n2);
}
catch (Exception e)
{
System.out.println("error :"+e+" idiot!, by 0?");
}
}
}
search
Monday, June 7, 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment