Giter Site home page Giter Site logo

ctc-cs-2018-ankith's Introduction

CTC-CS-2018-ANKITH

Problem 1

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".

solution:

#include <iostream>
#include<math.h>
using namespace std;
int a,b,r,i,j,res=0;
int bin(int n)
{
    int dec=0;
    for(i=0; n!=0; i++)
    {
        r=n%10;
        dec=dec+(r*pow(2,i));
        n=n/10;
    }
    return dec;
}
int decTobin(int res)
{
    int d[100],result[100],c=0;
    for(i=0; res>0; i++)
    {
        d[i]=res%2;
        res=res/2;
        //cout<<d[i];
    }
    c=i-1;
    i=c;
    for(j=0; j<=c; j++,i--)
    {
        result[j]=d[i];
        cout<<result[j];
    }
}
int main()
{
    int decA,decB;
    cout<<"Enter value for a"<<endl;
    cin>>a;
    decA=bin(a);
    cout<<"Enter value for b"<<endl;
    cin>>b;
    decB=bin(b);
    res=decA+decB;
    cout<<res<<endl;
    cout<<"Addition of "<<a<<" and "<<b<<" is ";
    decTobin(res);
}

ctc-cs-2018-ankith's People

Contributors

iloveyougit avatar ankithbala avatar

Watchers

James Cloos avatar

ctc-cs-2018-ankith's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.