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

Programs Questions and Answers

Question :: 101
Given an unsorted array and an item K, write a program to get kth largest element.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include<iostream>#include<algorithm>using namespace std; /* Function to return k'th smallest element in a given array */int kthSmallest(int arr[], int n, int k){    /* Sort the given array */    sort(arr, arr+n);     /* Return k'th element in the sorted array */    return arr[k-1];} /* Driver program to test above methods */int main(){    int arr[] = {12, 3, 5, 7, 19};    int n = sizeof(arr)/sizeof(arr), k = 2;    cout << "K'th smallest element is " <<  kthSmallest(arr, n, k);    return 0;}
``````

Tags:Adobe

Question :: 102
Given a sorted array and an item k, write a program to get a pair of items whose subtraction equal to K.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include <stdio.h>
#include<iostream>
using namespace std;
/* The function assumes that the array is sorted */
bool findPair(int arr[], int size, int n)
{
/* Initialize positions of two elements */
int i = 0;
int j = 1;
/* Search for a pair */
while (i<size && j<size)
{
if (i != j && arr[j]-arr[i] == n)
{
cout<<"Pair Found: "<< arr[i]<<"and"<< arr[j];
return true;
}
else if (arr[j]-arr[i] < n)
j++;
else
i++;
}
cout<<"No such pair";
return false;
}

/* Driver program to test above function */
int main()
{
int arr[] = {1, 8, 30, 40, 100};
int size = sizeof(arr)/sizeof(arr);
int n = 60;
findPair(arr, size, n);
return 0;
}
``````

Tags:Adobe

Question :: 103
Write a program to delete a node in single linklist, if address of that node is given.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include<stdio.h>#include<assert.h>#include<stdlib.h>#include<iostream>using namespace std; struct Node{    int data;    struct Node* next;}; void push(struct Node** head_ref, int new_data){    /* allocate node */   struct Node* new_node =             (struct Node*) malloc(sizeof(struct Node));   new_node->data  = new_data;   /* link the old list off the new node */   new_node->next = (*head_ref);   /* move the head to point to the new node */   (*head_ref)    = new_node;}void printList(struct Node *head){   struct Node *temp = head;   while(temp != NULL)   {     cout<< temp->data;      temp = temp->next;   }}void deleteNode(struct Node *node_ptr){   struct Node *temp = node_ptr->next;   node_ptr->data    = temp->data;   node_ptr->next    = temp->next;   free(temp);} /* Drier program to test above function*/int main(){    /* Start with the empty list */    struct Node* head = NULL;    /* Use push() to construct below list    1->12->1->4->1  */    push(&head, 1);    push(&head, 4);    push(&head, 1);    push(&head, 12);    push(&head, 1);     cout<<"\n Before deleting \n";    printList(head);    /* I m deleting the head itself.        You can check for more cases */   deleteNode(head);   cout<<"\n After deleting \n";   printList(head);   getchar();}
``````

Tags:Adobe

Question :: 104
Write a Program to sort the number 100001110101 in one traverse.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include<iostream>using namespace std;int main(){    int val, num, sum = 0;     cout << "Enter the number : ";    cin >> val;    num = val;    while (num != 0)    {        sum = sum + num % 10;        num = num / 10;    }    cout << "The sum of the digits of "         << val << " is " << sum;}
``````

Tags:Adobe

Question :: 105
write a program to reverse all the word in given sentence . Ex. India is a Great Country. Output: aidni si a taerg yrtnuoc.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include <stdio.h>#include <string.h>#include<iostream>using namespace std;void main(){    int i, j = 0, k = 0, x, len;    char str, str1, temp;     cout<<"enter the string :";   cin>> str;/* reads into 2d character array */    for (i = 0;str[i] != '\0'; i++)    {        if (str[i] == ' ')        {            str1[k][j]='\0';            k++;            j=0;        }        else        {            str1[k][j]=str[i];            j++;        }    }    str1[k][j] = '\0'; /* reverses each word of a given string */    for (i = 0;i <= k;i++)    {        len = strlen(str1[i]);        for (j = 0, x = len - 1;j < x;j++,x--)        {            temp = str1[i][j];            str1[i][j] = str1[i][x];            str1[i][x] = temp;        }    }    for (i = 0;i <= k;i++)    {        cout<<str1[i];    }}
``````
Question :: 106
write a program to set the nth bit .

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
int num, n, newNum;
/*Reads a number from user*/
cout<<"Enter any number: ";
cin>>num;
/*Reads the bit number you want to set*/
cout<<"Enter nth bit to set (0-31): ";
cin>>n;
/*Right shift 1 to n times and perform bitwise OR with number*/
newNum = (1 << n) | num;
cout<<"Bit set successfully.\n\n";
cout<<"Number before setting bit: in \n"<<"in"<<num<<"is"<<n;
cout<<"Number after setting bit:" <<"in"<<newNum<<"is"<<n;
return 0;
}

``````
Question :: 107
lets 32bit no. write a program to circular rotate 1 byte. int y=0x01020304; output y=0x04010203;

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include<stdio.h>
#include<iostream>
using namespace std;
#define INT_BITS 32
int leftRotate(int n, unsigned int d)
{
return (n << d)|(n >> (INT_BITS - d));
}
int rightRotate(int n, unsigned int d)
{
return (n >> d)|(n << (INT_BITS - d));
}
/* Driver program to test above functions */
int main()
{
int n = 16;
int d = 2;
cout<<"Left Rotation of" <<n<< "by "<<d<<" is ";
cout<<leftRotate(n, d);
printf("\nRight Rotation of"<<n<< "by "<<d<<" is ";
cout<< rightRotate(n, d);
getchar();
}

``````
Question :: 108
Write a program to check the bit is set or not.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include <stdio.h>
#include<iostream>
using namespace std;
void main()
{
unsigned int number;
int result, position;
cout<<"Enter the unsigned integer:\n";
cin>>number;
cout<<"enter position to be searched\n";
cin>>position;
result = (number >> (position));
if (result & 1)
cout<<"TRUE\n";
else
cout<<"FALSE\n";
}
``````
Question :: 109
Write a program to find the loop in linklist and remove the loop in linklist.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include <stdio.h>#include <stdlib.h>#include<iostream>using namespace std;struct node{    int val;    struct node *next;};void print_list(struct node *head){    cout<<"H->";    while(head)    {        cout<< head->val;        head = head->next;    }    cout<<"|||\n";}void insert_front(struct node **head, int value){    struct node * new_node = NULL;    new_node = (struct node *)malloc(sizeof(struct node));    if (new_node == NULL)    {        cout<<"Failed to insert element. Out of memory";    }    new_node->val = value;    new_node->next = *head;    *head = new_node;}void create_loop(struct node *head){    struct node *tmp = head;    while(tmp->next) tmp = tmp->next;    tmp->next = head->next;}void print_loop(struct node *head){    int n = 25;    cout<<"H->";    while(n--)    {        cout<<head->val;        head = head->next;    }    cout<<"|||\n";}void detect_loop(struct node *head){    struct node *slow = head;    struct node *fast = head;    while(slow && fast->next && fast->next->next)    {        if ((slow == fast->next) || (slow == fast->next->next ))        {            cout<<"Linked list has a loop.\n";            return;        }        slow = slow->next;        fast = fast->next->next;    }    cout<<"Linked list does not have any loop.\n";}void remove_loop(struct node *head, struct node *loop_node){    struct node *near = head;    struct node *far = head;    struct node *ptr = loop_node;    struct node *prev = NULL;    while(ptr->next != loop_node)    {        ptr = ptr->next;        far = far->next;    }    prev = far;    far = far->next;    while(near != far)    {        prev = far;        far = far->next;        near = near->next;    }    prev->next = NULL;}void detect_and_remove_loop(struct node *head){    struct node *slow = head;    struct node *fast = head;    while(slow && fast->next && fast->next->next)    {        if ((slow == fast->next) || (slow == fast->next->next ))        {            cout<<"Linked list has a loop.\n";            remove_loop(head, slow);            return;        }        slow = slow->next;        fast = fast->next->next;    }   cout<<"Linked list does not have any loop.\n";}void main(){    int count = 0, i, val;    struct node * head = NULL;    cout<<"Enter number of elements: ";  cin>>count;    for (i = 0; i < count; i++)    {        cout<<"Enter ith element: "<< i;        cin>>val;        insert_front(&head, val);    }    cout<<"Original List: ";    print_list(head);    detect_loop(head);    cout<<"Creating loop...\n";    create_loop(head);    cout<<"Printing list with loop";    print_loop(head);    detect_loop(head);    cout<<"Removing loop...\n";    detect_and_remove_loop(head);    detect_loop(head);    cout<<"List after removing loop:\n";    print_list(head);}
``````
Question :: 110
Can you write a program to implement memcpy. copy must be successful even source and destination address overlap.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience
Answer In:
``` ```
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;void myMemCpy(void *dest, void *src, size_t n){char *csrc = (char *)src;char *cdest = (char *)dest;for (int i=0; i<n; i++)    cdest[i] = csrc[i];}int main(){char csrc[] = "GeeksforGeeks";char cdest;myMemCpy(cdest, csrc, strlen(csrc)+1);cout<<"Copied string is "<<cdest;int isrc[] = {10, 20, 30, 40, 50};int n = sizeof(isrc)/sizeof(isrc);int idest[n], i;myMemCpy(idest, isrc, sizeof(isrc));cout<<"\nCopied array is ";for (i=0; i<n; i++)    cout<< idest[i];return 0;}
``````