Saturday, 3 October 2015

C Programs Asked in Interview - Interview Questions

C Programs list are shared in this post which are generally asked in campus interviews. We tried our level best to make you understand each program in detail and we have collected this list of C programs asked in interview by many experienced candidates who have appeared such interviews.

Frequently asked C Programs in Interviews:


Write a C program to find factorial of the given number.
Using Loop:
#include <stdio.h>

int main()
{
    int i, n, fact=1;
    
    printf("Enter a number to get its factorial:");
    scanf("%d", &n);
    
    for(i=1; i<=n; i++)
    {
        fact = fact * i;
    }
    
    printf("Factorial of %d is %d\n", n, fact);

    return 0;
}
Using Function:
#include <stdio.h>

int factorial(int x);

int main()
{
    int n, fact;
    
    printf("Enter a number to find its factorial:");
    scanf("%d", &n);
    
    fact = factorial(n);
    printf("Factorial of %d is %d\n", n, fact);
}

int factorial(int x)
{
    int i, a = 1;
    for(i=1; i<=x; i++)
    {
        a = a * i;
    }
    
    return a;
}
Using Recursion:
#include <stdio.h>

int factorial(int x);

int main()
{
    int n, fact;
    
    printf("Enter a number to find its factorial:");
    scanf("%d", &n);
    
    fact = factorial(n);
    printf("Factorial of %d is %d\n", n, fact);
}

int factorial(int x)
{
    if(x==0 || x==1)
    {
        return 1;
    }
    return x * factorial(x-1);
}

Write a C program to check whether the given number is even or odd.

Write a C program to swap two numbers without using a temporary variable.

Write a C program for reversing a string without using function.

Write a C program to check whether the given number is a prime.
Using Loop: Using Function:
Write a C program to generate the Fibonacci series.
Using Loop: Using Recursion:
Write a C program to print "Hello World" without using semicolon anywhere in the code.
Method 1: Method 2: Method 3:
Write a C program to compare two strings without using strcmp() function.

Write a C program to concatenate two strings without using strcat() function.

Write a C program to delete a specified line from a text file.
Write a C program to replace a specified line in a text file.
Write a C program to find the number of lines in a text file.
WAP to check a string is Palindrome or not.

WAP to print the triangle of letters in increasing order of lines.

We will be covering up all above programs in details in a separate post. I hope this will help you to clear technical interview round with ease. If you have more sets of questions which are generally asked then you are most welcome to add a comment below, we will update that in this list.

0 comments

Post a Comment