Common Logical Questions Asked in a Technical Interview

Common Logical Questions Asked in a Technical Interview

Well, if you are going for a technical interview in any programming language, in any stream, irrespective of your expertise and experience, you could be asked very simple logical questions which you must know. Interviewer can ask you very basic and famous C programs to check your logic which you had done in very early stage of your life like Fibonacci Series, Factorial Number, Palindrome Number, Prime Numbers etc. You should be able to write down the logic of these basic programs in a minute otherwise it might be very embarrassing for you and will put direct negative impact on the interviewer.

All your domain knowledge, programming language hold could be negated if you get stuck in these problems. So I must advise you to have a quick look on these algorithms before you appear in any technical interview.

Fibonacci Series: To print Fibonacci series up to n numbers

int main()
{
   int n, first = 0, second = 1, next, c;

   printf("Enter the number of terms\n");
   scanf("%d",&n);

   printf("First %d terms of Fibonacci series are :-\n",n);

   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }
   return 0;
}

Factorial Program: To find out factorial of a number 

int main()
{
  int c, n, fact = 1;

  printf("Enter a number to calculate it's factorial\n");
  scanf("%d", &n);

  for (c = 1; c <= n; c++)
    fact = fact * c;

  printf("Factorial of %d = %d\n", n, fact);

  return 0;
}

Palindrome Number: To check whether a given number is palindrome or not?

int main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);

   return 0;
}

Prime Number: To check whether a given number is prime number or not?

int isPrime(int);

int main(){

    int num,prime;

    printf("Enter a positive number: ");
    scanf("%d",&num);

    prime = isPrime(num);

   if(prime==1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);

   return 0;
}

int isPrime(int num){

    int i=2;

    while(i<=num/2){
         if(num%i==0)
             return 0;
         else
             i++;
    }

    return 1;
}

Please do add some more basic programs or algorithms you need to know before going to a technical interview.