Monday 29 August 2016

Program for Decimal to Binary Conversion

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ Program for Decimal to Binary Conversion

#include<bits/stdc++.h>

using namespace std;

int main()
{
    long dec,rem,i=1,sum=0,binary=0;
    cout<<"Enter the decimal to be converted:";
    cin>>dec;

    while(dec!=0)
    {
      rem=dec%2;
      dec/=2;
      binary+=rem*i;
      i*=10;
    }

    cout<<"The binary of the given number is:"<<binary<<endl;

    return 0;
}

Program for Binary to Decimal Conversion

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ Program to Convert Binary To Decimal


#include<bits/stdc++.h>

using namespace std;

int main()
{
    long bin, dec = 0, rem, num, base = 1;

    cout << "Enter the binary number";
    cin >> num;
    bin = num;
    while (num > 0)
    {
        rem = num % 10;
        dec = dec + rem * base;
        base = base * 2;
        num = num / 10;
    }
    cout << "The decimal equivalent of " << bin << " : " << dec << endl;
    return 0;

}

Saturday 27 August 2016

Ratio of Two Numbers

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ PROGRAM TO FIND RATIO OF TWO NUMBERS

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int first_number, second_number,ans,t,gcd;

    cin>>first_number>>second_number;

    int a=first_number;

    int b=second_number;

    while (b != 0) {
     t = b;
     b = a % b;
     a = t;
    }

    gcd = a;

    printf("%d/%d",first_number/gcd,second_number/gcd);

    return 0;
}

Power Finding Program

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ PROGRAM FOR FINDING POWER

#include <bits/stdc++.h>
using namespace std;

int main() {
    int exp;
    float base, power = 1;

    cin >> base >> exp;

    while (exp != 0) {
        power *= base;
        --exp;
    }

    cout << "Result = " << power;
    
    return 0;
}

L.C.M and H.C.F Program

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++  PROGRAM  FOR  FINDING  H.C.F.  &  L.C.M.



#include<bits/stdc++.h>
 
int main() 
{
  int a, b, x, y, t, gcd, lcm;
 
  cin>>a>>b;
 
  a = x;
  b = y;
 
  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }
 
  gcd = a;
  lcm = (x*y)/gcd;
 
  cout<<gcd<<endl;
  cout<<hcf<<endl;
 
  return 0;
}

Friday 26 August 2016

Logical XOR Program

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ Program for Logical XOR of two Decimal Numbers


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int first_number, second_number,ans;

    cin>>first_number>>second_number;

    ans=first_number^second_number;

    cout<<ans<<endl;

    return 0;
}

Logical OR Program

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ Program for Logical OR of two Decimal Numbers


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int first_number, second_number,ans;

    cin>>first_number>>second_number;

    ans=first_number|second_number;

    cout<<ans<<endl;

    return 0;
}

Logical AND Program

www.programmingcalculator.com

C++ Program for Logical  AND of Two Decimal Numbers


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int first_number, second_number,ans;

    cin>>first_number>>second_number;

    ans=first_number&second_number;

    cout<<ans<<endl;

    return 0;
}

Monday 1 August 2016

Barracuda networks (A Bangalore's Startup) written Round Programming Questions


1) C program to copy one file to another.


#include<bits/stdc++.h>

using namespace std;

int main()
{
    char ch,src[20],tgt[20];
    FILE *s,*t;

    gets(src);
    s=fopen(src,"r");
    if(s==NULL)
    {
        printf("press any key to exit\n");
        exit(EXIT_FAILURE);
    }


    gets(tgt);
    t=fopen(tgt,"w");
    if(t==NULL)
    {
        printf("press any key to exit\n");
        exit(EXIT_FAILURE);
    }


    while(( ch=fgetc(s))!=EOF)
        fputc(ch,t);

    return 0;

}


-----------------------------------------------------------------------------------------------------------------------

2 ) use function pointer to add , sub and multiply

#include<bits/stdc++.h>

using namespace std;

int add(int a,int b)
{
return a+b;
}


int sub(int a,int b)
{
return a-b;
}


int mul(int a,int b)
{
return a*b;
}


int main()
{
    typedef int (*a)(int,int); /// a is now declared as type

    a fp[3]={add, sub ,mul};

 int n;
 cin>>n;
 int c,b;
 cin>>c>>b;

if(n==0)
    cout<<fp[0](c,b)<<endl;
else if(n==1)
    cout<<fp[1](c,b)<<endl;
else
    cout<<fp[2](c,b)<<endl;

return 0;
}

DMX technologies (A Bangalore's Startup) written Round Programming Questions

1) Spiral Matrix Printing 
  
For example : if given n=2 , then output is   3 2 
                                                                      0  1

                       if given n=3 , then output is   4  3  2
                                                                      5  0  1
                                                                      6  7  8 


C++ Program 

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    int a[n+1][n+1];
    int num=n*n-1;

    for(int i=1,j=n;i<=n,j>=0;i++,j--)
    {
        for(int k=i;k<=j;k++)                              ///upper row
            a[i][k]=num--;

        for(int k=i+1;k<=j;k++)
            a[k][j]=num--;

        for(int k=j-1;k>=i;k--)
            a[j][k]=num--;

        for(int k=j-1;k>i;k--)
            a[k][i]=num--;

           // if(num<0) break;
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            cout<<a[i][j]<<"   ";
              cout<<endl;
    }

    return 0;

}

-------------------------------------------------------------------------------------------------------------------------

2) All Permutations of a given string using Recursion 

Link :- http://nikhilnihal.blogspot.in/2016/07/printing-all-permutation-of-string.html



Uploading and Running Lambda function in AWS

Main.go package main import ( "fmt" "encoding/json" "log" "github.com/aws/aws-lambda-g...