Friday, September 13, 2013

Tagged Under:

Top Programs asked in C interviews

Share

Top Programs asked in C interviews !

As C, Cpp (C Plus Plus/ C++) is the most basic programming language, and a pre-requisite for any technical computer science interview. Most of the questions asked in interviews are not that typical, they are basically to judge the thinking capability, problem solving ability, and the basic knowledge of the language.
Here is an compiled list of few most common C interview questions along with their solutions to give a basic idea about the type of the questions and solving strategies.

Ques : Write a program to find out if a given number is a power series of 2 or not, without any loop and without using % modulo operator.

Solution:
#include
#include<stdio.h>
#include<conio.h>

int power(float);
void main()
{
 int i,c;
 clrscr();
 printf("Enter the number\n") ;
 scanf("%d",&i);
 c=power(i);
 if(c)
  printf("\n %d is power series of 2",i);
 else
  printf("\n %d is not a power series of 2",i);
 getch();
}

int power(float j)
{
 static float x;
 x=j/2;
 if(x==2)
  return 1;
 if(x)
  return 0;
 x=power(x);
}

Ques : Write a program in C to remove duplicasy in string.
Solution:
#include
#include
void main()
{
 int i,j,k=0,count[300]={ 0};
 char ch,str[1000],str1[1000];
 clrscr();
 printf("\n Enter the string to remove duplicasy\ n:");
 gets(str);
 for (i=0;str[i ]!='\0';i+ +)
  {
   ch=str[i];
   count['']=0; 
   if(count[ch])
    continue;
   else
    {
     str1[k++]=ch;
     count[ch]=1;
    }
  }
 puts(str1);
 getch();
}
Ques: Write a program to print 'XAY' in place of every 'a' in string.
Solution: 
#include<stdio.h>
#include<conio.h>
void main()
{
 int i=0;
 char str[100],x='x'y='y' ;
 clrscr();
 printf("Enter the string :");
 gets(str);
 while(str[i]!='\0')
 {
  if(str[i]= ='a')
   {
    printf("%c",x);
    printf("%c",str[i++] );
    printf("%c",y);
   }
  else
   {
    printf("%c ",str[i++] );
   }
 }
 getch();
}