The smallest no. such that if its rightmost digit is placed at its left end, the new number so formed is precisely 50% larger than the original no.

Ques Find the smallest number such that if its rightmost digit is placed at its left end, the new number so formed is precisely 50% larger than the original number.

Answer The answer is 285714. If its rightmost digit is placed at its left end, then new number is 428571 which is 50% larger than the original number 285714.

l.w= 28….28*2+1 = 57…28/2 = 14

Sum of last digit = sum of rest digits

Consider a number 235, where last digit is the sum of first two digits i.e. 2 + 3 = 5. How many such 3-digit numbers are there? **Ans **There are 45 different 3-digit numbers. Take the combinations The last digit can not be 0. If the last digit is 1, the only possible number is 101. (Note that 011 is not a 3-digit number) If the last digit is 2, the possible numbers are 202 and 112. [Read More]

What is a void pointer? Why can't we perform arithmetic on a void * pointer?

The void data type is used when no other data type is appropriate. A void pointer is a pointer that may point to any kind of object at all. It is used when a pointer must be specified but its type is unknown. The compiler doesn’t know the size of the pointed-to objects incase of a void * pointer. Before performing arithmetic, convert the pointer either to char * or to the pointer type you’re trying to manipulate [Read More]

Program to check if the stack grows up or down

#include 
#include 

void stack(int *local1);

int main()
{
  int local1;
  stack(&local1);
  exit(0);
}

void stack(int *local1)
{
   int local2;
   printf("\nAddress of first  local : [%u]", local1);
   printf("\nAddress of second local : [%u]", &local2);
   if(local1 < &local2)
   {
     printf("\nStack is growing downwards.\n”);
   }
   else
   {
     printf("\nStack is growing upwards.\n”);
   }
   printf("\n\n”);
}

To swap the two nibbles in a byte

#include 

unsigned char swap_nibbles(unsigned char c)
{
  unsigned char temp1, temp2;
  temp1 = c & 0x0F;
  temp2 = c & 0xF0;
  temp1=temp1 « 4;
  temp2=temp2 » 4;

  return(temp2|temp1); //adding the bits
}

int main(void)
{
  char ch=0x34;
  printf("\nThe exchanged value is %x”,swap_nibbles(ch));
  return 0;
}

What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?

A null pointer simply means “I am not allocated yet!” and “I am not pointing to anything yet!”. The C language definition states that for every available pointer type, there is a special value which is called the null pointer. It is guaranteed to compare unequal to a pointer to any object or function. A null pointer is very different from an uninitialized pointer. A null pointer does not point to any object or function; but an uninitialized pointer can point anywhere. [Read More]

WAP to check whether string is palindrome

Problem Write a method which will accept a string and return true if the string is a palindrome and false if it isn’t. Follow up: a) your method should consider lower case and upper case characters to be the same. b) your method should ignore special characters and white spaces, for e.g. if your input were the strings were “Madam, I’m Adam!!”, then you should consider it a palindrome and hence return true ignoring case and special characters. [Read More]

A program to print numbers from 1 to 100 without using loops

Method1 (Using recursion)

void printUp(int startNumber, int endNumber) {   if (startNumber > endNumber)     return;     printf("[%d]\n", startNumber++);   printUp(startNumber, endNumber); }

Method2 (Using goto)

`
void printUp(int startNumber, int endNumber)
{
start:

    if (startNumber > endNumber)
    {
       goto end;
    }
    else
    {
       printf("[%d]\n”, startNumber++);
       goto start;
    }

end:
    return;
}`

Code to check if an integer is a power of 2 or not in a single line

Problem Check if integer is power of 2 or not FOLLOW UP - Preferable solution to get it in 1 line. Solution Method1 All power of two numbers have only one bit set. So count the no. of set bits and if you get 1 then number is a power of 2. We have discussed how to count number of bits set here. Method 2 Note that the bit pattern of a power of two is of the form 10…0 and that of a number just one less is 011…1. [Read More]