Submitted Questions

  • Binary

    Write a program that continues to ask the user to enter any decimal number and calculate it’s binary,octal and hexadecimal equivalent.

    Badugu

    • Mar 11th, 2015

    Please try following:

    Code
    1. #include<iostream>
    2. #include<fstream>
    3. #include <bitset>
    4.  
    5. using namespace std;
    6.  
    7. int main()
    8. {
    9.     int i,j;
    10.     cout<<"Enter a decimal Number:";
    11.     while (cin>>i) {
    12.                  
    13.           cout<<"Hexa Decimal:"<<std::hex<<i<<"     Octal:"<<std::oct<<i<<endl;
    14.           std::bitset<8> x(i);
    15.           cout<<"Binary:"<<x<<endl;
    16.           cout<<"Enter a decimal Number:";
    17.           }
    18.          
    19.           return 0;
    20.           }
    21.  

    rohit suri

    • Sep 11th, 2014

    Code
    1.  
    2. int binary_function(int num)
    3. {
    4.    if(num==1)
    5.       return 1;
    6.   else
    7.     return binary_function(num/2)*10+(num%2);
    8. }
    9.  

  • Number in words

    Write a program that takes an integer and displays the words number of that value. For example, 10->ten 121->one hundred twenty one

    Subrata Laha

    • Jul 25th, 2014

    Please see the below code in Java"java import java.text.DecimalFormat; public class EnglishNumberToWords { private static final String[] tensNames = { "", " ten", "...

  • Permutations

    Write a program to display all possible permutations of a given input string--if the string contains duplicate characters, you may have multiple repeated results. Here is a sample for the input cat cat,cta,act,atc,tac,tca

    Jin Hyuk Cho

    • Feb 3rd, 2016

    A working example

    Code
    1. #include <iostream>
    2. #include <string>
    3. #include <set>
    4. #include <sstream>
    5.  
    6. using namespace std;
    7.  
    8. void permute (set<char> &chars, set<string> &permuted) {
    9.     if (chars.size() == 1) {
    10.         stringstream charSS;
    11.         charSS << *(chars.begin());
    12.         permuted.insert(charSS.str());
    13.         return;
    14.     }
    15.     for (set<char>::iterator it = chars.begin(); it != chars.end(); ++it) {
    16.         // constructing remaining characters
    17.         set<char> remainingChars(chars);
    18.         remainingChars.erase(*it);
    19.         // constructing empty set for results
    20.         set<string> permutedRemainingStrings;
    21.         permute(remainingChars, permutedRemainingStrings);
    22.         for (set<string>::iterator rit = permutedRemainingStrings.begin();
    23.              rit != permutedRemainingStrings.end();
    24.              ++rit) {
    25.             stringstream ss;
    26.             ss << *it << *rit;
    27.             string onePermute = ss.str();
    28.             //cout << onePermute << endl;
    29.             permuted.insert(onePermute);
    30.         }
    31.     }
    32. }
    33. int main () {
    34.    
    35.     ostream_iterator<string> output(cout, " " );
    36.     set<char> chars = {c, a, t};
    37.     set<string> permuted;
    38.     permute(chars, permuted);
    39.     copy(permuted.begin(), permuted.end(), output);
    40.     cout << "Done!" << endl;
    41.    
    42.    
    43.     return 0;
    44. }

    neha

    • Aug 27th, 2015

    plz see below code"cpp #include #include using namespace std; void Permutations(string str) { for(int i = 0; i < str.size(); i++) ...