Problem 18

8 comments on “Problem 18”


  • SRIHARI TIRUMALAGUDIMELLA

    #include
    #include
    int main(int argc, char *argv[])
    {
    int sum;

    if(argc == 1){
    printf(“enter number”);
    }
    else{
    int i,j,r,a[10];
    sum = atoi(argv[1]) + atoi(argv[2]);
    printf(“sum %d\n”,sum);

    for(i=0;sum>0;i++)
    {
    r = sum%2;
    a[i] = r;
    sum = sum/2;

    }
    printf(“binary format is\n”);
    for(j=i-1;j>=0;j–)
    {
    printf(“%d”,a[j]);
    }
    }
    return 0;
    }


  • avi gehlot

    #Addition of 2 numbers and printing the result in binary
    a,b=map(int, input().split(” “))
    sum=a+b
    x=bin(sum).replace(“0b”,” “)

    print(“binary Addition is :”,x)


  • sachin kushwah

    /* using c program*/

    #include
    void main()
    {
    int a,b,c,rem,arr[100],count=0;
    printf(“Enter two numbers \n”);
    scanf(“%d %d”,&a,&b);
    c=a+b;
    printf(“Addition of commandn line is %d”,c);
    while(c)
    {
    rem=c%2;
    arr[count]=rem;
    count++;
    c=c/2;
    }
    printf(“\nBinary Representation “);
    while(count)
    {
    printf(“%d”,arr[count-1]);
    count–;
    }

    }


  • Hritik

    //Addition of 2 numbers and printing the result in binary Using Command Line Programming

    #include
    void binary(int,int);
    int main(){
    int a,b,res;
    scanf(“%d%d”,&a,&b);
    binary(a+b,2);
    }
    void binary(int n,int base){
    int rem;
    if(n==0)
    return;
    rem = n%base;
    binary(n/base,base);
    printf(“%d”,rem);
    }


  • Mohd Saif

    #python

    n1,n2=map(int,input(“Enter the two number n1 and n2:\n”).split(” “))
    sum=n1+n2
    x=bin(sum)
    print(f”The addition of {n1} and {n2} is:{sum} and its binary representation is {x}”)


  • Ravisankar ka

    public class NewClass6 {
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int sum=a+b;
    System.out.println(Integer.toBinaryString(sum));
    }
    }


  • Tanaya

    #include
    #include
    int main(int argc,char *argv[])
    {
    if(argc0)
    {
    rem=sum%2;
    binary+=rem*base;
    base=base*10;
    sum=sum/2;
    }
    printf(“%d”,binary);
    return 0;
    }
    }