//Program to Calculate Sum of two nos without arithmetic operator
//Program by Ahlam Ansari
import java.util.*;
class AddMain
{
public static void main(String ahlam[])
{
int carry, a, b;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the two numbers");
a=sc.nextInt();
b=sc.nextInt();
while (b!=0)
{
carry=a&b;
a^=b;
b=carry<<1;
}
System.out.print(a);
}
}
/*
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>javac AddMain.java
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>java AddMain
Enter the two numbers
3
4
7
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>
*/
//Program by Ahlam Ansari
import java.util.*;
class AddMain
{
public static void main(String ahlam[])
{
int carry, a, b;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the two numbers");
a=sc.nextInt();
b=sc.nextInt();
while (b!=0)
{
carry=a&b;
a^=b;
b=carry<<1;
}
System.out.print(a);
}
}
/*
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>javac AddMain.java
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>java AddMain
Enter the two numbers
3
4
7
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>
*/
No comments:
Post a Comment