Microsoft Interview Question for Program Managers


Team: Windows Azure
Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 2 vote

Hope this answer helps.

#include <stdio.h>
#include <stdlib.h>

int main ()
{
  char ipAddr[] = "192.168.1.256";
  int a=0,b=0,c=0,d=0;
  int con = sscanf(ipAddr, "%d.%d.%d.%d", &a, &b, &c, &d);
  if ( 4 == con )
  {
    printf("scanned ip=%s had %d octets\n a=%d, b=%d, c=%d, d=%d\n", ipAddr, con, a, b, c, d);
    if ((0<=a && a<=255) && (0<=b && b<=255) && (0<=c && c<=255) && (0<=d && d<=255) )
      printf("valid ip address\n");
    else
      printf("not valid ip address\n");
  }
  else
  {
    printf("malformed ip address\n");
  }
 return 0;

}

Regards,
~Nazir

- peacelover September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

First part of an ip address can't start with 0. it must between 1 and 255. other parts can between 0 and 255.

- dogukan.demir September 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//It will definitely work- in the last program it was taking always 4 octets. modification done in sscanf statement //

#include <stdio.h>
#include <stdlib.h>

int main ()
{
char ipAddr[20]; //= "192.168.1.255";
scanf("%s",ipAddr);
int a=0,b=0,c=0,d=0,e=0;
int con = sscanf(ipAddr, "%d.%d.%d.%d.%d", &a, &b, &c, &d, &e);
if ( con == 4 )
{
printf("scanned ip=%s had %d octets\n a=%d, b=%d, c=%d, d=%d\n", ipAddr, con, a, b, c, d);
if ((0<=a && a<=255) && (0<=b && b<=255) && (0<=c && c<=255) && (0<=d && d<=255) )
printf("valid ip address\n");
else
printf("not valid ip address\n");
}
else
{
printf("malformed ip address\n");
}
return 0;

}

- Rohit Pratap Singh February 24, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More