Posts

Showing posts from 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; }

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 ; }

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; }

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; ...

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                                                                   ...

Printing all the permutation of the string using recursion

           dog    dog ,  odg ,  god    (in first call 1st character is swapped with all postions (1st to last)) dgo     ogd       gdo   (in 2nd call ,2nd character is swapped with all postions(2nd to last) ) #include<bits/stdc++.h> using namespace std; void permu(string k,int fst,int lst) {     if(fst==lst)         cout<<k<<endl;     for(int i=fst;i<=lst;i++)     {         swap(k[fst],k[i]);         permu(k,fst+1,lst);         swap(k[fst],k[i]);     } } int main() {     string s;     cin>>s;     int lst=s.size()-1;     permu(s,0,lst);     return 0; }

Reverse String using Recursion C++

Here the Logic is simple to print the last character of the string for each function call and again call the reverse function again ,this time the string doesn't contain last character. #include<bits/stdc++.h> using namespace std; void reve(string k) {   int sz=k.size();   if(sz==1)     cout<<k[sz-1];   else   {      cout<<k[sz-1];      string p=k.substr(0,sz-1);      reve(p);   } } int main() {     string s;     cin>>s;     reve(s);     return 0; }

LeadSquared Interview Questions

On 12th july , I got a chance to sit for the written round of Leadsquared drive. In 1 hour we have to do 3 java questions. 1st question->Excel sheet problem                       ex. 1 -> A , 2->B , 26->Z ,27->AA   import java.util.*; public class excel { public static void main(String args[]) {   Scanner s=new Scanner(System.in);        int r,n=s.nextInt();   String k=" ";        while(n>0)   { r=n%26;           if(r==0)  { String ch="Z";             k=k+ch; n=n/26 -1;  }           else  {  int ch=r-1+(int)'A';  char p=(char)ch;  String h= Character.toString(p);               k=k.concat(h);          n=n/26; ...

c++ Program to reverse the sentence

C++ Program to reverse the sentence Input- "My name is Nikhil" Output "Nikhil is name My" Here the idea to reverse each word in 1st phase and in 2nd phase reverse the whole sentence. #include<bits/stdc++.h> using namespace std; int main() {     string s;     getline(cin,s);     cout<<s<<endl;     int l=s.size();     int pre=0;     for(int i=0;i<l;i++)     {       if(s[i]==' ')       {         int k=i-1;         while(pre<k){char c=s[pre]; s[pre]=s[k]; s[k]=c; pre++; k--; }         pre=i+1;       }       else if(i==l-1)       {         int k=i;         while(pre<k){char c=s[pre]; s[pre]=s[k]; s[k]=c; pre++; k--; }       }     }     int bck=0; ...

Directi Online Interview Question :- Two non-overLapping subarrays of size k which gives maximum sum

Directi Online Interview Question. Two non-overLapping subarrays of size k which gives maximum sum. This is a 1-D Dp approach ,in O(n) time-complexity. #include<bits/stdc++.h> using namespace std; int pre[1000],a[10000],dp[1000]; int main() {     int n,k;     cin>>n>>k;     for(int i=1;i<=n;i++) cin>>a[i];         pre[0]=0;         pre[1]=a[1];         dp[k]=pre[k];    ///upto length k     for(int i=2;i<=n;i++) pre[i]=pre[i-1]+a[i];     for(int i=k+1;i<=n;i++) dp[i]=max(dp[i-1],pre[i]-pre[i-k]);     int ans=0;     for (int i=k;i<=n;i++){     ans = max(ans,dp[i-k]+pre[i]-pre[i-k]);}     cout<<ans<<endl;     return 0; }

Women safety and security android app

Image
                                                Download Link: https://play.google.com/store/apps/details?id=comm.Kishlay.screamDetector&hl=en "Chilla" is a personal safety & security app that can be triggered by just a shrill scream . It totally removes the hassles of unlocking the phone or opening the app. It has been found that in cases where someone follows a girl / women or eve-teases her , she generally doesn't calls out to parents or police and if they attack her , the app is of no use to her then. In that situation scream is a natural reaction and tapping that is the best possible way to bring her help. The apps can be triggered by: 1. Scream 2.Pressing power Button 5 times After Trigger, it does the following 1.Sends SMS with location 2.Sends Email with Audio Recording 3.Automatically places a call If a scream is detected the a...