NVIDIA Interview Question for Software Engineer / Developers






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

void hex(int num){
int rem;
if(!num)
return;
hex(num/16) ;
rem=num%16;
printf("%c",(rem<10)? '0'+rem :('A'+rem-10));
return;
}

- ridercoder October 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

printhex(int a){
if (a <10 )
printf(%d,a);
else
if (a <16)
printf (%c, 55+a);
else
 
}

- neo August 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

2nd else wont work!!! already comparing it with 10....

- Anonymous August 27, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@neo
incomplete code...

@CUNOMAD
what exactly you mean by saying "implements %x in printf without using printf"... not clear enough.

- googler August 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@googler u cant use standard %x for printing

- cunomad August 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@cunomad
then the question shud be: print the hex value without using the default %x available in printf for the same...anyways you've to use printf finally, right?

- googler August 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we cant use printf

- cunomad August 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

lol
the first solution uses printf. if printf is not allowed then what is the answer?

- lol August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

char getHex(int num)
{
     if (num < 10 )
        return (char)(num+48);
     if (num < 16 )
        return (char)(num+55);
}

int printhex(int x)
{
    // Convert the input to HEX
    char tmpresult[100];
    char result[100];
    int remainder=0, indx=0, i = 0, j = 0;
    while(x)
    {
       remainder = x%16;
       x = x/16;
       tmpresult[indx++] = getHex(remainder);
    }

    for ( int i=0, j=indx-1; i < indx ; i++, j--)
       result[j] = tmpresult[i];
    // write to output
    write(1, result, indx);
    return 0;
}

int main(int argc, char* argv[])
{
   printhex(atoi(argv[1]));
   return 0;
}

- Anonymous September 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is for positive numbers only...

- Bhanu Patial September 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

char getHex(int num)
{
     if (num < 10 )
        return (char)(num+48);
     if (num < 16 )
        return (char)(num+55);
}

int printhex(int x)
{
    if ((x/16 == 0) && (x < 16))
    {
        putchar(getHex(x%16));
        return 0;
    }
    printhex(x/16);
    putchar(getHex(x%16));
}


int main(int argc, char* argv[])
{
   printhex(atoi(argv[1]));
   return 0;
}

- Bhanu Patial September 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string itoh(int i)
{
stringstream ss;
ss<<hex<<i;
std::string retval;
retval=ss.str().c_str();
return retval;
}

- Pratik July 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int hex(int num);
void main()
{
int num;
printf("Enter value for num \n");
scanf("%d",&num);
printf("Hexadecimal number is : ");
hex(num);
printf("\b\n\n");
}

int hex(int num)
{
if(num<16)
{
if((num)<10)
printf("%d",num);
else
printf("%c",'A'+num-10);
return 0;
}
else
{
if((num/16)<10)
printf("%d",num/16);
else
printf("%c",'A'+(num/16)-10);
hex(num%16);
}
}

- Kunal Bansal December 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printhex(int a)

{

for (int i = 0; i < 32; i += 4) {

int c = (a >> i) & 0xF;

if (c <= 9)

putchar(‘0’ + c);

else

putchar(‘a’ + c - 10);

}
}

- engineer November 27, 2013 | 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