Saturday, December 5, 2015

HCL interview question(Written)::Noida

Two programming questions asked by the HCL interviewing team.
Question 1::
Write a program in C/C++ which takes input as string "12345" and output will be:: 1+2+3+4+5=15.

I have written it in C. Below is the code.

Answer::

/* Input(as string)::"12345" and
output should be:: 1+2+3+4+5=15 */

#include<stdio.h>
#include<conio.h>
void main()
{
    char str1[]="12345";
    int i,sum=0;
    for(i=0;i<sizeof(str1)-1;i++)
    {
        printf("%d",(int)str1[i]-48);
        sum = sum + (int)str1[i]-48;
        if(i!=sizeof(str1)-2)
            printf("+");
    }
    printf(" = %d",sum);
}


Question 2:

Create two threads.
One thread prints only odd numbers 1 3 5 7 ...
other thread prints only even numbers 2 4 6 8 ...
But the output should be mixed of both :; 1 2 3 4 5 6 7 8 ...  upto n.

I had not worked in threads, so I have implemented the program in two function.
 If any one having idea of threads then please give the program, thanks in advance.
My program was as below::


#include<iostream>
using namespace std;
static int a,b;
void t_odd()
{
    a+=2;
    cout<<" "<<a;
}
void t_even()
{
    b+=2;
    cout<<" "<<b;
}

int main()
{
    a = -1; b = 0;
    int i,n;
     cout<<"enter the value n::";
    cin>>n;
    for(i=1;i<=n/2;i++)
    {
        t_odd();
        t_even();
    }
    if((n%2)!=0)
        t_odd();
    return 0;
}

Friday, October 23, 2015

How to use Beetel Adsl2 + Router-450TC1 as switch and Wifi router only

Once I had a problem that I had two ADSL Wifi Routers, one was connected to WAN (Phone line, since I was having Airtel broadband connection) but other one was extra. I wanted to use the extra one as wifi router. But I was not getting how to do this !!

After searching a lot in internet finally I found the solution.

Things required-
1. LAN cable to connect two routers.
2. desktop/Laptop

All below settings are changed in Extra modem. Do not change any setting in the primary modem which is connected to WAN.

1. Reset the extra modem to factory setting.
Steps to reset -
* Press the resent button. You can easily find it in back of the router. 
* Press the resent button and wait for 30 seconds while plugged in and cut the power while continue       to press it for next 10 seconds. 
* Now power on the router.

2. Now use LAN cable to connect router and your Desktop or Laptop. 

3. Now access you router by entering the address 192.168.1.1 in your browser. It will connect you to the router.

4. Now change the default IP address used to access the router. Both router must have different address to access them. Generally it remain 192.168.1.1. You can change it to 192.168.1.2.

5. Now open the 192.168.1.2(it may be different, depends upon what you set in 2nd step above) in your browser. 

6. Under interface section choose bridge mode.

7. Disable to DHCP mode.

8. Change the Wifi name under SSID name and password under Pre Shared key.

9. Restart the modem.

All done..You must be able to access internet over LAN and wifi from secondary modem.
Enjoy..