Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.


Please wait...

  Take Quiz (Monsoon) Beta Version !!
  Do You have Qs. in your Mind ??? Ask it as Qs. or MCQs or create it as polling Live Now !!

Programs Questions and Answers



    71 / 348

    Write a program, swapping function by passing value using call by reference?

    Input : NA


    Output : NA

    View Answer |  Basics |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++   PHP  
     
    #include <iostream>
    using namespace std;
    /* function declaration */
    void swap(int &x, int &y);
    int main () {
       /* local variable declaration: */
       int a = 100;
       int b = 200;
       cout << "Before swap, value of a :" << a << endl;
       cout << "Before swap, value of b :" << b << endl;
       /* calling a function to swap the values using variable reference.*/
       swap(a, b);
       cout << "After swap, value of a :" << a << endl;
       cout << "After swap, value of b :" << b << endl;
       return 0;
    }

    72 / 348

    Make 3 nodes in doubly linked list and delete the 2nd node. Use pointer as ptr. Write the program for same.

    Input : NA


    Output : NA

    View Answer |  Trees |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++  
     
    #include <stdio.h>
    #include <stdlib.h>
    # include <iostream>
    using namespace std; 
    struct node
    {
        struct node *prev;
        int n;
        struct node *next;
    }*h,*temp,*temp1,*temp2,*temp4;
    void insert1();
    void insert2();
    void insert3();
    void del();
    int count = 0;
    void main()
    {
        int ch;
        h = NULL;
        temp = temp1 = NULL;
        cout<<"\n 1 - Insert at beginning";
        cout<<"\n 2 - Insert at end";
        cout<<"\n 3 - Insert at position i";
        cout<<"\n 4 - Delete at i";
        cout<<"\n 5 - Exit";
        while (1)
        {
            cout<<"\n Enter choice : ";
            cin>>ch;
            switch (ch)
            {
            case 1:
                insert1();
                break;
            case 2:
                insert2();
                break;
            case 3:
                insert3();
                break;
            case 4:
                del();
                break;
            case 5:
                exit(0);
            default:
                printf("\n Wrong choice menu");
            }
        }
    }
     
    /* TO create an empty node */
    void create()
    {
        int data;
     
        temp =(struct node *)malloc(1*sizeof(struct node));
        temp->prev = NULL;
        temp->next = NULL;
        cout<<"\n Enter value to node : ";
        cin>>data;
        temp->n = data;
        count++;
    }
     
    /*  TO insert at beginning */
    void insert1()
    {
        if (h == NULL)
        {
            create();
            h = temp;
            temp1 = h;
        }
        else
        {
            create();
            temp->next = h;
            h->prev = temp;
            h = temp;
        }
    }
     
    /* To insert at end */
    void insert2()
    {
        if (h == NULL)
        {
            create();
            h = temp;
            temp1 = h;
        }
        else
        {
            create();
            temp1->next = temp;
            temp->prev = temp1;
            temp1 = temp;
        }
    }
     
    /* To insert at any position */
    void insert3()
    {
        int pos, i = 2;
     
        cout<<"\n Enter position to be inserted : ";
        cin>>pos;
        temp2 = h;
     
        if ((pos < 1) || (pos >= count + 1))
        {
            cout<<"\n Position out of range to insert";
            return;
        }
        if ((h == NULL) && (pos != 1))
        {
            cout<<"\n Empty list cannot insert other than 1st position";
            return;
        }
        if ((h == NULL) && (pos == 1))
        {
            create();
            h = temp;
            temp1 = h;
            return;
        }
        else
        {
            while (i < pos)
            {
                temp2 = temp2->next;
                i++;
            }
            create();
            temp->prev = temp2;
            temp->next = temp2->next;
            temp2->next->prev = temp;
            temp2->next = temp;
        }
    }
     
    /* To delete an element */
    void del()
    {
        int i = 1, pos;
     
        cout<<"\n Enter position to be deleted : ";
        cin>>pos;
        temp2 = h;
     
        if ((pos < 1) || (pos >= count + 1))
        {
            cout<<"\n Error : Position out of range to delete";
            return;
        }
        if (h == NULL)
        {
            cout<<"\n Error : Empty list no elements to delete";
            return;
        }
        else
        {
            while (i < pos)
            {
                temp2 = temp2->next;
                i++;
            }
            if (i == 1)
            {
                if (temp2->next == NULL)
                {
                   cout<<"Node deleted from list";
                    free(temp2);
                    temp2 = h = NULL;
                    return;
                }
            }
            if (temp2->next == NULL)
            {
                temp2->prev->next = NULL;
                free(temp2);
                cout<<"Node deleted from list";
                return;
            }
            temp2->next->prev = temp2->prev;
            if (i != 1)
                temp2->prev->next = temp2->next;    /* Might not need this statement if i == 1 check */
            if (i == 1)
                h = temp2->next;
            cout<<"\n Node deleted";
            free(temp2);
        }
        count--;
    }

    Tags:Wipro

    73 / 348

    Write a program to print below pattern. * ** *** ****

    Input : NA


    Output : NA

    View Answer |  Basics |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++   JAVA   PHP  
     
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int main()
    {
       int row, c, n, temp;
       cout<<"Enter the number of rows in pyramid of stars you wish to see ";
       cin>>n;
       temp = n;
       for ( row = 1 ; row <= n ; row++ )
       {
          for ( c = 1 ; c <= row; c++ )
           cout<<c;
          cout<<"\n";
       }
       return 0;
    }

    Tags:Wipro

    74 / 348

    Write an efficient program to find the length of a string.

    Input : NA


    Output : NA

    View Answer |  Strings |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++   PHP  
     
    #include <iostream>
    
    using namespace std;
    int main()
    {
        string str = "C++ Programming";
        /* you can also use str.length() */
        cout << "String Length = " << str.size();
        return 0;
    }

    Tags:No Tags on this question yet!

    75 / 348

    Write a program to find the number is power of 2 or not.

    Input : NA


    Output : NA

    View Answer |  Basics |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++   JAVA  
     
    #include<stdio.h>
    #include<iostream>
    using namespace std;
    #define bool int
    /* Function to check if x is power of 2*/
    bool isPowerOfTwo (int x)
    {
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
    }
    /*Driver program to test above function*/
    int main()
    {
    isPowerOfTwo(31)?cout<<"Yes\n": cout<<"No\n";
    isPowerOfTwo(16)? cout<<"Yes\n": cout<<"No\n";
    return 0;
    }

    76 / 348

    Write a program to find the LCM and GCD.

    Input : NA


    Output : NA

    View Answer |  Basics |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++   JAVA   PHP  
     
    #include <stdio.h>
     #include <iostream>
    using namespace std;
    void main()
    {
        int num1, num2, gcd, lcm, remainder, numerator, denominator;
       cout<<"Enter two numbers\n";
        cin>> num1>>num2;
        if (num1 > num2)
        {
            numerator = num1;
            denominator = num2;
        }
        else
        {
            numerator = num2;
            denominator = num1;
        }
        remainder = numerator % denominator;
        while (remainder != 0)
        {
            numerator   = denominator;
            denominator = remainder;
            remainder   = numerator % denominator;
        }
        gcd = denominator;
        lcm = num1 * num2 / gcd;
        cout<<"GCD of "<< num1<<" and "<< num2<<" is "<< gcd;
        cout<<"LCM of "<< num1<<" and "<< num2<<" is "<< lcm;
    }

    Tags:PEOL

    77 / 348

    Write a program to merge two sorted array.

    Input : NA


    Output : NA

    View Answer |  Array |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   C++   PHP  
     
    #include <stdio.h> 
    #include <iostream>
    using namespace std;
    void main()
    {
        int array1[50], array2[50], array3[100], m, n, i, j, k = 0;
        cout<<"\n Enter size of array Array 1: ";
        cin>>m;
        cout<<"\n Enter sorted elements of array 1: \n";
        for (i = 0; i < m; i++)
        {
            cin>>array1[i];
        }
        cout<<"\n Enter size of array 2: ";
        cin>>n;
        cout<<"\n Enter sorted elements of array 2: \n";
        for (i = 0; i < n; i++)
        {
            cin>>array2[i];
        }
        i = 0;
        j = 0;
        while (i < m && j < n)
        {
            if (array1[i] < array2[j])
            {
                array3[k] = array1[i];
                i++;
            }
            else
            {
                array3[k] = array2[j];
                j++;
            }
            k++;
        }
        if (i >= m)
        {
            while (j < n)
            {
                array3[k] = array2[j];
                j++;
                k++;
            }
        }
        if (j >= n)
        {
            while (i < m)
            {
                array3[k] = array1[i];
                i++;
                k++;
            }
        }
        cout<<"\n After merging: \n";
        for (i = 0; i < m + n; i++)
        {
            cout<<"\n"<<array3[i];
        }
    }

    78 / 348

    Write a function to test if the given set of brackets are balanced or not.

    Input : {{}}{)([][]


    Output :

    View Answer |  Stack |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In: C   PHP  
     
    <!DOCTYPE html>
    <html>
    <body>
    <?php
    function Balance()
    {
        
    $arr       = array(
            
    "[",
            
    "}",
            
    "]",
            
    "(",
            
    "{",
            
    "(",
            
    ")"
        
    );
        
    $arrlength count($arr);
        
    $count1    0;
        
    $count2    0;
        
    $count3    0;
        for (
    $x 0$x $arrlength$x++) {
            if (
    $arr[$x] == "(")
                
    $count1++;
            if (
    $arr[$x] == ")")
                
    $count1--;
            if (
    $arr[$x] == "{")
                
    $count2++;
            if (
    $arr[$x] == "}")
                
    $count2--;
            if (
    $arr[$x] == "[")
                
    $count3++;
            if (
    $arr[$x] == "]")
                
    $count3--;
        }
        if (
    $count1 == 0)
            echo 
    "brackets () are balanced<br/>";
        else
            echo 
    "brackets () are not balanced<br/>";
        if (
    $count2 == 0)
            echo 
    "brackets {} are balanced<br/>";
        else
            echo 
    "brackets{} are not balanced<br/>";
        if (
    $count3 == 0)
            echo 
    "brackets []are balanced<br/>";
        else
            echo 
    "brackets [] are not balanced<br/>";
        
        
    }

    Balance(); //function calling
    ?>  

    </body>
    </html>

    79 / 348

    Write a function to find the permutation of given string.

    Input : NA


    Output : NA

    View Answer |  Strings |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In:
     No Discussion on this question yet!

    80 / 348

    Write a function to convert first letter of matching string to capital letter.

    Input : This chain applies to packets received via a network interface. Matching String: packets.


    Output : This chain applies to Packets received via a network interface.

    View Answer |  Strings |  Discuss in Forum | Add to Reading List To Reading List | Asked In |  Fresher
    Answer In:
     No Discussion on this question yet!