C questions and answers

C questions and answers with explanation

1. Data types        2. Operators              3. Pointers
4. Arrays            5. Loops                  5. Preprocessor
6. Structures        6. If else                6. Switch case
7. printf            8. Variables              7. File handling
8. Strings           9. Command line arguments

C questions and answers for interview

Online Tests

1. Practice set 1    2. Practice set_2         3. Practice set_3  

C tutorials:

1. Memory mapping    2. Variables              3. Data types
4. Storage Class     5. Looping                5. Pointers
6. Functions         6. Arrays                 6. Preprocessor
7. File handling     8. Advance c             
C pdf to free download

1. Faq pdf           2. C in depth pdf         3. MCQ pdf 
4. Objective 1 pdf   5. C langauge pdf         6. C questions pdf
7. Pointers pdf      6. Interview pdf          8. C Test 1 pdf

Good tricky questions
1. Best c questions   2. Tricky c questions      3. MCQ  4. C in Linux 

C program examples FAQ:

1. Fibonacci series    2. Check prime number        3. Find factorial
4. Check Palindrome    5. Reverse string            6. Check Armstrong                
7. Quadratic equation  9. Concatenate string          8. Reverse numbers  

C programs on numbers
1. Sum of digits        2. Find Power       3. Addition(Without using +)

13. Check odd or even   14. Find nCr       15. Multiplication table

C program on strings

1. Upper to Lower      2. Lower to upper      3. Print initials
4. Delete consonants   5. String palindrome   6. Sort the characters

LCM and HCF

1. LCF          2. HCF              3. GCD

Sorting

1. Selection sort    2. Quick sort            3. Insertion sort
4. Bubble sort       5. Merge sort             6. Heap

sort

Searching

1. Linear search     2. Binary search

Swapping

1. Two numbers       2. Swap two string        3. Swap two arrays

Conversion

1. Binary to decimal     2. Binary to octal      3. Binary to hex
7. Octal to binary       8. Octal to decimal     9. Octal to hex
10. Hex to binary        11. Hex to decimal      12. Hex to Octal               
13. Decimal to Roman     14. Roman to decimal    15. Digits to word 
16. Currency to word     17. Units conversion    18. String to int

Matrix

1. Addition         2. Subtraction          3. Multiplication
4. Division         5. Transport            6. Sum of diagonal elements
7. Inverse          8. Determinants         9. Scalar multiplication

File

1. Write text and close     2. Delete a file 3. Copy from one 
location to other           4. Copy data of file
5. Display source code as output     6. Write string in the file
11. Find size and drive of file      12. Know type of file          

Complex number

1. Print complex number    2. Addition & subtraction    
3. Multiplication
4. Division

Array


C program using function recursion

1. Factorial         2. Prime number           3. Fibonacci series  
4. GCD               5. Palindrome             6. Reverse string
7. LCM               8. Multiplication         9. Sum of digits
10. Find power       11. Reverse number      
12. Sum of n numbers 
13. Binary search    14. Decimal to binary      15.Matrix multiplication    

Print different Shapes


Sum of Series

4. A.P.                5. G.P.                6. H.P.

Area and volume

1. Circle       2. Triangle       3. Equilateral triangle         4.Rectangle     5. Trapezium      6. Parallelogram  
7. Right angled triangle          8. Rhombus 
9. Cylinder     10. Cube          11. Cuboids         
12. Cone        
13. Sphere        14. Perimeters

Find Size of data types (Without using sizeof)

1. int         2. double         3. struct              4. union

Operation on very large number (Beyond long int)

1. Multiplication          2. Division          3. Modular          
5. Factorial of 1000       6. Power             7. More c codes

Miscellaneous

1. C++ programs            2. Java programs

64 comments:

  1. please write the program for follwing
    if u enter number between 2 to 9 it will display like
    5=1,1,1,1,1
    5=1,1,1,2
    5=1,1,3
    5=1,4
    5=2,1,1,1
    5=2,2,1
    5=3,1,1
    5=4,1

    ReplyDelete
  2. good.. very useful

    ReplyDelete
  3. please write a program for following:
    write a program to delete all vowels from a sentence.Assume that the sentence is not more than 80 characters long.

    ReplyDelete
  4. please write a program for following:
    write a program which will read a line and squeeze out all blanks from it and output the line with no blanks.

    ReplyDelete
    Replies
    1. #include<stdio.h>

      int main(){

      char str[100];
      char squeeze[100];
      int i=0,j=0;

      scanf("%[^\n]",str);

      while(str[i] != '\0'){

      if(str[i] != 32)
      squeeze[j++] = str[i]; i++;

      }

      squeeze[j] = '\0';

      printf("%s",squeeze);

      return 0;

      }

      Sample Output:
      c programming lanaguage
      cprogramminglanaguage

      Delete
  5. i want c program conects to sql server displays global time zone??

    ReplyDelete
  6. Qlxchange : Ha detto: interessante

    ReplyDelete
  7. hi i want programme on combination example "ENGINEER" possible combinations on this string using recursion function
    thanks

    ReplyDelete
  8. Your site is very good.

    ReplyDelete
  9. nice article...
    i can learn my knowledge from this site...thanks for sharing this excellent site...i hope keep writing...

    ReplyDelete
  10. Really helpful.Thanks a lot! Never knew selfless people like this exist. Thanks a ton!

    ReplyDelete
  11. what will be output of this please solve


    #include

    main()

    {

    int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };

    int *p,*q;

    p=&a[2][2][2];

    *q=***a;

    printf("%d----%d",*p,*q);

    }

    ReplyDelete
  12. Thanks for the Information you share with me
    Regards
    Education Portal

    ReplyDelete
  13. Write a program to input 10 integers and sort them. Use a menu system to determine
    whether the sort should be ascending or descending order. The process should continue
    till the user desires to exit.

    ReplyDelete
  14. wap to find the height of the wall if the height of the ladder and the inclination of the ladder from the ground is given by the user.
    how to solve the above question in c.

    ReplyDelete
    Replies
    1. #include<stdio.h>
      #include <math.h>

      #define PI 3.141592653589793238462643383

      int main(){

      float h = 10;
      double inclation = PI/6;
      float p;

      p = h * sin(inclation );

      printf("Height of wall %lf",p);

      return 0;

      }

      Delete
  15. Given two arrays of size n, exactly one number is missing in the second array of the elements of first array. Write a function to return the missing number.

    ReplyDelete
    Replies
    1. #include<stdio.h>

      int main(){

      int arr1[5]= {1,2,3,4,5};
      int arr2[5]= {3,1,5,2};
      int i,j;
      int flag;

      for(i=0;i<5;i++){

      flag =0;

      for(j=0;j<5;j++){

      if(arr1[i] == arr2[j]){

      flag = 1;
      break;

      }
      }

      if(flag ==0){

      printf("Missing element in arr2 is: %d",arr1[i]);
      break;

      }
      }

      return 0;

      }

      Delete
    2. /******************
      Using one for loop and no need of comparison of numbers one by one.
      ******************/

      #define SIZE 5
      int main()
      {
      int arr1[SIZE] = {1,2,3,4,5};
      int arr2[SIZE-1] = {3,1,5,2};

      int sum1 = 0, sum2 = 0,i;

      for(i=0; i < SIZE-1; i++)
      {
      sum1 = sum1 + arr1[i];
      sum2 = sum2 + arr2[i];
      }
      sum1 = sum1 + arr1[i];

      printf("Missing number : %d \n", sum1 - sum2);
      }

      Delete
  16. hey every body ...
    ive recently found this site ... its very awesome ...

    iam trying to sort a 2-dimensional array (in ascending order) based on the sum of each row.

    this is an example;
    input
    1 5 7
    2 4 3
    1 3 2
    7 0 1
    ........
    output
    1 3 2
    7 0 1
    2 4 3
    1 5 7

    can anybody help me with this ...

    ReplyDelete
    Replies
    1. #include<stdio.h>

      int main(){

      int arr[4][3]= {{1,5,7},{2,4,3},{1,3,2},{7,0,1}};
      int temp[1][3];
      int i,j,l=4;

      for(i=0;i<l;i++){
      for(j=i+1;j<l;j++){

      if(arr[i][0] + arr[i][1] + arr[i][2] > arr[j][0] + arr[j][1] + arr[j][2]){

      temp[0][0]=arr[i][0];
      temp[0][1]=arr[i][1];
      temp[0][2]=arr[i][2];

      arr[i][0]=arr[j][0];
      arr[i][1]=arr[j][1];
      arr[i][2]=arr[j][2];

      arr[j][0]=temp[0][0];
      arr[j][1]=temp[0][1];
      arr[j][2]=temp[0][2];
      }
      }
      }

      for(i=0;i<l;i++){
      printf("%d %d %d \n",arr[i][0],arr[i][1],arr[i][2]);
      }

      return 0;
      }

      Delete
  17. Dear Mr. ritesh kumar,

    thank you very much. it was a great help. i really appreciate

    ReplyDelete
  18. please write a program in c to find complement of a set

    ReplyDelete
  19. Thanks for easy C tutorials.

    ReplyDelete
  20. hi ... can you write a program in C to find determinant of a Eigenvalue problem 2X2 & 3X3... please ... please.... I need It very fast ... thank you.

    ReplyDelete
  21. if u introduce about hailhoods series amd dice it would be nice

    ReplyDelete
  22. hi ... can you Write a program to find the area of a circle (2*pi*R) where R=Radius. (using functions)

    ReplyDelete
  23. I found this very informative thank you

    ReplyDelete
  24. best site ever

    ReplyDelete
  25. thank u very much.
    thank u thank u
    thank u.

    ReplyDelete
  26. please make a program for finding sinx using following series
    sinx = x - x^3/3! + x^5/5! - x^7/7! + .... + x^n/n!

    ReplyDelete
  27. Can u make program for collecting the students personal info and store it in a files by allocating memory dynamically..... pls

    ReplyDelete
  28. write a program to create a file of structure.the file should have all the particuler of citizen who pay income tax like permanent account number,name,address,tax number and year.

    ReplyDelete
  29. please add the examples for structures and link list or suggest any link... and please ex plane union,type def .

    ReplyDelete
  30. please write an algorithm for swap sorting that uses the minimum number of swaps to sort a circular permutation

    ReplyDelete
  31. Write a code that determines the BER for a simple detector for a digital communication
    system. A digital communication system can be described as follows: a transmitter sends a
    sequence of 0’s and 1’s to a designated receiver. Due to non­ideal wireless transmission, the
    transmitted sequence is erroneously received due to the presence of noise. The noise is a
    random signal that is added to each bit of the transmitted sequence and changes its value at
    each bit. For example, you can send the following sequence 1 0 1 0 1 0 and the noise value at
    each bit happens to be something like 0.2 0.4 ­0.3 0.3 ­0.5 ­0.3 so the received signla will be like
    1.2 0.4 0.7 0.3 0.5 ­0.3. In order to detect the sequence, a receiver compares the received value
    to a threshold of 0.5. If the received signal is greater than 0.5, a bit is decoded as 1, else it is
    decoded as 0. You are required to generate a sequence of bits, add noise to each bit and
    calculate the Bit Error Rate (BER) which is   number of errors in the sequence/length of the
    sequence. Noise generation could be done by the function rand you have to repeat the
    transmission many times and find the average error rate. For example: a transmission of [ 1 0 0
    0 1 1 0 0 0 0], and noise of [0 0.3 0.4 0.6 0 0 0.1 0.2 ­0.3 ­0.2] will give one error at the 4th
    element, i.e ber 1/10.
    i cant do it plz help me :)

    ReplyDelete
  32. devlop a structure 'formula-one'. member should include driver's name lapnumber along with completion time for each lap,age of driver. devlop the function getdata() to get data from the user. showdata() to display the data of particular driver and average()to display the average laptime of each driver.use main function to call these functions. please solve this question.

    ReplyDelete
  33. Program to multiply 2 numbers without using multiplication symbol(Hint: add first number the number of times the second number)


    give me the answer

    ReplyDelete
  34. post prog in c and explanation

    implementaion for stack ,queue
    conversion of infix to postfix

    ReplyDelete
  35. Hi bro, i was just trying to make a LUDO game for C, i just made the board of it, and the game is for just 2 players, just wondering, how can i create a function that moves the tokens, watch it out
    #include
    #include
    #include
    #define F2 2//Codigo de ficha 2 para que no cambie de valor nunca y se mantenga el caracter especial cara RELLENA
    #define F1 1 //Codigo de ficha 1 para que no cambie de valor nunca y se mantenga el caracter especial cara VACIA
    #define B2 219 //COdigo para la base de la ficha 2, cuadrado RELLENO
    #define B1 176 //COdigo para la base de la ficha 1, cuadrado VACIO
    #define D123 254 //Codigo para que aparezcan dados imaginarios, es un cuadrado relleno con codigo ascii 254

    void movf1(int *ptr){



    int main(){
    /*COmenzamos el tablero desde arriba*/
    /*fila11, a21 caracter especial de comienzo de partida*/
    int a19=1, a20=1, a21=31;
    printf("0 0 0 0 %i-%i-%c 0 0 0 0\n", a19, a20, a21);
    /*fila 10, f4 caracter especial de cuadrado, aplicacion de la constante F2*/
    int a18=1, f1=B2, a22=1, c1=F2, c2=F2;
    printf("0 0 0 0 %i %c %i 0 %c %c 0\n", a18, f1, a22, c1, c2);
    /*fila 9, f3 caracter especial cuadrado, aplicacion de la constante F2*/
    int a17=1, f2=B2, a23=1, c3=F2, c4=F2;
    printf("0 0 0 0 %i %c %i 0 %c %c 0\n", a17, f2, a23, c3, c4);
    /*fila 8*/
    int a16=1, f3=B2, a24=1;
    printf("0 0 0 0 %i %c %i 0 0 0 0\n", a16, f3, a24);
    /*fila 7*/
    int a11=1, a12=1, a13=1, a14=1, a15=1, f4=B2, a25=1, a26=1, a27=1, a28=1, a29=1;
    printf("%i-%i-%i-%i-%i %c %i-%i-%i-%i-%i\n", a11, a12, a13, a14, a15, f4, a25, a26, a27, a28, a29);
    /*fila 6*/
    int a10=1, a30=1;
    printf("%i 0 0 0 0 0 0 0 0 0 %i\n", a10, a30);
    /*fila 5*/
    int a9=1, a8=1, a7=1, a6=1, a5=1, e4=B1, a35=1, a34=1, a33=1, a32=1, a31=1;
    printf("%i-%i-%i-%i-%i %c %i-%i-%i-%i-%i\n", a9, a8, a7, a6, a5, e4, a35, a34, a33, a32, a31);
    /*fila 4, caracter especial en e3 base blanca codigo ascii 176*/
    int a4=1, e3=B1, a36=1;
    printf("0 0 0 0 %i %c %i 0 0 0 0\n", a4, e3, a36);
    /*fila 3*/
    int b1=F1, b2=F1, a3=1, e2=B1, a37=1, d1=D123, d2=D123, d3=D123;
    printf("0 %c %c 0 %i %c %i %c %c %c 0\n", b1, b2, a3, e2, a37, d1, d2, d3);
    /*fila 2*/
    int b3=F1, b4=F1, a2=1, e1=B1, a38=1;
    printf("0 %c %c 0 %i %c %i 0 0 0 0\n", b3, b4, a2, e1, a38);
    /*fila 1, a1 inicio de partida caracter especial*/
    int a1=30, a40=1, a39=1;
    printf("0 0 0 0 %c %i %i 0 0 0 0", a1, a40, a39);

    /*DEFINIENDO 56 Punteros, en las ubicaciones que variaran*/
    //fila1
    int *z1=&a1;
    int *z40=&a40;
    int *z39=&a39;
    //FILA 2
    int *y3=&b3;
    int *y4=&b4;
    int *z2=&a2;
    int *v1=&e1;
    int *z38=&a38;
    //fila 3
    int *y1=&b1;
    int *y2=&b2;
    int *z3=&a3;
    int *v2=&e2;
    int *z37=&a37;
    //fila4
    int *z4=&a4;
    int *v3=&e3;
    int *z36=&a36;
    //fila 5
    int *z9=&a9;
    int *z8=&a8;
    int *z7=&a7;
    int *z6=&a6;
    int *z5=&a5;
    int *v4=&e4;
    int *z35=&a35;
    int *z34=&a34;
    int *z33=&a33;
    int *z32=&a32;
    int *z31=&a31;
    //fila 6
    int *z10=&a10;
    int *z30=&a30;
    //fila 7
    int *z11=&a11;
    int *z12=&a12;
    int *z13=&a13;
    int *z14=&a14;
    int *z15=&a15;
    int *u4=&f4;
    int *z25=&a25;
    int *z26=&a26;
    int *z27=&a27;
    int *z28=&a28;
    int *z29=&a29;
    //fila 8
    int *z16=&a16;
    int *u3=&f3;
    int *z24=&a24;
    //fila 9
    int *z17=&a17;
    int *u2=&f2;
    int *z23=&a23;
    int *x3=&c3;
    int *x4=&c4;
    //fila 10
    int *z18=&a18;
    int *u1=&f1;
    int *z22=&a22;
    int *x1=&c1;
    int *x2=&c2;
    //fila 11
    int *z19=&a19;
    int *z20=&a20;
    int *z21=&a21;



    getch();
    return 0;
    }

    ReplyDelete
  36. Very very usefull and good site

    thank you very much

    ReplyDelete
  37. Can you send me the practical usages of NULL POINTERS?????

    ReplyDelete
  38. I have a doubt... is it true that a++ is faster than a=a+1 ?

    ReplyDelete
    Replies
    1. Abhisek go through this link
      http://www.cquestions.com/2010/03/why-i-is-faster-than-ii1-in-c.html

      Delete
  39. Q. Significance of primility testing in formulation of public key cryptography algorithm.
    can any one provide some agenda what to do and how to do this assignment?

    ReplyDelete
  40. hey please solve my question:
    write a program to find out how many tiles of 25 sq.cms can be fitted in a plot of 100 sq. mtrs

    ReplyDelete
  41. hey please solve my question:
    write a program to find out how many tiles of 25 sq.cms can be fitted in a plot of 100 sq. mtrs
    if u know thee answer please mail me at rohanvgosalia@gmail.com

    ReplyDelete
  42. can you tell me how i write a c programme a given number is prime or not

    ReplyDelete
  43. Please help me, i want to implement a prefix expression in c - linux using fork and pipe without files and stacks,
    such as: ( + ( + 8 9) ( * 7 5)) = 52
    please the deadlock in 27/11/13

    ReplyDelete
  44. create a quee programfor following function using link list
    a.create
    b.display
    c.print left to right
    d.print right to left
    e.replace
    f.count no of node

    ReplyDelete
  45. sir this is excellent.can u tell me any good site of data structure

    ReplyDelete
  46. Write a program which asks user name of a text file. Once the user enters the name,
    your program will try to open it. If there is no such file (i.e. the user enters a wrong file
    name), your program will not crash and warn the user with an error message.
    Once the text file is opened successfully, your program will provide the following
    functionalities in a menu:
    1. Find: In selection of this choice, your program will ask the user a word. Once
    the user enters the word, then the program will search for this word in the text
    file and returns the number of occurrences in the file.
    2. Find & Replace: In addition to the previous option, your program will ask two
    words the user (word1 and word2). Then the program will search the word1 in
    the file and replaces them with word2. In this option, make sure that you open
    the file for read and write enable.

    hİ , Can you help me please , HOW DO I DO THAT ?

    ReplyDelete
  47. Can any one able to solve following:

    Define a structure called cricket with player name, team name, and batting average.
    Declare an array of player with 5 elements. Write a program to read the information
    about all the 5 players and print a team-wise list containing names of players with
    their batting average.

    ReplyDelete
  48. i have a problem in java program .can anybody solve it
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class ComboxDemo extends Applet implements ItemListener
    {
    int i,pr;
    String msg="";
    Choice two,three,op;
    public void init()
    {
    two=new Choice();
    three=new Choice();
    op=new Choice();
    for(i=1;i<=10;i++)
    {
    pr=2*i;
    two.add(""+pr);
    }
    for(i=1;i<=10;i++)
    {
    pr=3*i;
    three.add(""+pr);
    }
    op.add("+");
    op.add("-");
    op.add("*");
    op.add("%");
    add(two);
    add(three);
    add(op);
    two.addItemListener(this);
    three.addItemListener(this);
    op.addItemListener(this);
    }
    public void itemStateChanged(ItemEvent ie)
    {
    repaint();
    }
    public void paint(Graphics g)
    {
    msg="first n0.";
    msg+=two.getSelectedItem();
    g.drawString(msg,6,100);
    msg="second no :";
    msg+=three.getSelectedItem();
    g.drawString(msg,6,120);
    msg="operand ";
    msg+=op.getSelectedItem();
    g.drawString(msg,6,140);
    msg="result";
    msg+=two+" "+three;
    g.drawString(msg,6,160);
    }
    }
    in the above program i want to perform operation between tabels of 2 and 3.for thi what ihave to add in the program

    ReplyDelete
  49. Given The Positive Integer A,b And M With M>1 Find A^b Mod M Using C Program,, i need your help..

    ReplyDelete
  50. //how value of A=20
    # define SQR(X) (X*X)
    void main()
    {
    int a;
    a = SQR(6+2);
    printf(“\n%d”, a);
    }

    ReplyDelete
  51. Admin pls write a c program for finding the given number is odd r even without modulo operator..

    ReplyDelete
  52. Please help write a code to program inverse laplase of a function.

    ReplyDelete
  53. It is very useful for me

    ReplyDelete