CS Electrical And Electronics
@cselectricalandelectronics
All PostsC_languageInterview QuestionsProgramming

C Language Interview Questions On Programs With Output

Hello guys, welcome back to my blog. In this article, I will share c language interview questions on programs with output, c programming interview questions asked in companies like DXC, google, Amazon, Facebook, etc.

If you need an article on some other topics then comment us below in the comment box. You can also catch me @ Instagram – Chetan Shidling.

Also, read:

  1. Computer Science Engineers, Skills, Salary, Companies, Job profiles.
  2. Top Electrical Engineers Jobs In Private And Government Companies.
  3. Different Types Of Posts or Jobs For Electrical Engineers.

C Language Interview Questions

Nowadays, C language is asked in each and every interview whether you are from electrical and electronics, electronics, and communication, or computer science, etc they want to know your coding skills. You also read my tutorial on c language or c programing (C Programming Tutorial).

The C language is adopted as a system development language because it allows the code which runs so fast and too C language is also used to write code for smartwatches, several other products, and a number of back-end server network applications are written in C language. So, learning a C language is so valuable nowadays.

Let’s start C language interview questions on programs with output.

01. Write a C program to find factorial of any number?

#include<stdio.h>
int main()
{
int n,i;
int m=1;
printf("Enter number for factorial\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
m=m*i;
printf("value of factorial=%d\n",m);
//Chetan Shidling
return 0;
}
//CS Electrical & Electronics

Output:

Enter number for factorial
2
value of factorial=2
Enter number for factorial
5
value of factorial=120
Enter number for factorial
8
value of factorial=40320

02. Write a C program for the one-dimensional array to store elements in an array and find the smallest element in the array?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void small(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf("Enter array sizen");
scanf("%d",&n);
read(a,n);
display(a,n);
small(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf("Enter the array elementsn");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf("Array elements aren");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
//CS Electrical & Electronics
void small(int a[MAX],int n)
{
int i,sml,x=1;
sml=a[0];
for(i=1;i<n;i++)
{
if(a[i]<sml)
sml=a[i];
x=i+1;
}
printf("Smallest among all=%d\n",sml);
}

Output:

Enter array size
6
Enter the array elements
234
55
4
765
345
336
Array elements are
234
55
4
765
345
336
Smallest among all =4

03. Write a C program for the one-dimensional array to store elements in an array and also reverse the elements in an array then display the output?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void reverse(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf("Enter array size\n");
scanf("%d",&n);
read(a,n);
display(a,n);
reverse(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf("Array elements are\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
//CS Electrical & Electronics
void reverse(int a[MAX],int n)
{
int i,j,b[MAX];
for(i=n-1,j=0;i>=0;i--,j++)
b[j]=a[i];
for(i=0;i<n;i++)
a[i]=b[i];
printf("Reverse array is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}

Output:

Enter array size
5
Enter the array elements
23
456
456
23
455
Array elements are
23
456
456
23
455
Reverse array is
455
23
456
456
23

04. Write a C program for the one-dimensional array to store elements in an array and find the even and odd elements in the array?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void ans(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf("Enter array size\n");
scanf("%d",&n);
read(a,n);
display(a,n);
ans(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf("Array elements are\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
//CS Electrical & Electronics
void ans(int a[MAX],int n)
{
int i,q[MAX],r[MAX];
printf("elements even in array are\n");
for(i=0;i<n;i++)
{
int j=0;
if(a[i]%2==0)
{
q[j]=a[i];
printf("%d\n",q[j]);
j++;
}
}
printf("elements odd in array are\n");
for(i=0;i<n;i++)
{
int k=0;
if(a[i]%2!=0)
{
r[k]=a[i];
printf("%d\n",r[k]);
k++;
}
}
}

Output:

Enter array size
4
Enter the array elements
23
45
12
55
Array elements are
23
45
12
55
Elements even in array are
12
Elements odd in array are
23
45
55

05. Write a C program for the one-dimensional array to store elements in an array and find the largest element in the array?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void large(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf("Enter array size\n");
scanf("%d",&n);
read(a,n);
display(a,n);
large(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf("Array elements aren");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
//CS Electrical & Electronics
void large(int a[MAX],int n)
{
int i,larg,x=1;
larg=a[0];
for(i=1;i<n;i++)
{
if(a[i]>larg)
larg=a[i];
x=i+1;
}
printf("Largest among all=%d\n",larg);
}

Output:

Enter array size
4
Enter the array elements
12
3
555
3
Array elements are
12
3
555
3
Largest among all=555

06. Write a modular C program for the one-dimensional array to perform addition of elements present in odd and even index?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void sum(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf("Enter array size\n");
scanf("%d",&n);
read(a,n);
display(a,n);
sum(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d\n",&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf("Array elements are\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
//CS Electrical & Electronics
void sum(int a[MAX],int n)
{
int i,x=0,y=0;
for(i=0;i<n;i++)
{
if(i%2==0)
x=x+a[i];
else
y=y+a[i];
}
printf("Sum of elements in even index=%d\n",x);
printf("Sum of elements in odd index=%d\n",y);
}

Output:

Enter array size
4
Enter the array elements
2
3
2
4
Array elements are

2
3
2
4
Sum of elements in even index=4
Sum of elements in odd index=7

07. Write a C program to store and display the elements in different one-dimensional arrays?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
int main()
{
int n, a[MAX],b[MAX];
printf("Enter array size\n");
scanf("%d",&n);
read(a,n);
display(a,n);
read(b,n);
display(b,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX],int n)
{
int i;
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
//CS Electrical & Electronics
void display(int a[MAX],int n)
{
int i;
printf("Array elements are\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}

Output:

Enter array size
4
Enter the array elements
12
34
22
44
Array elements are
12
34
22
44
Enter the array elements
12
44
56
23
Array elements are
12
44
56
23

08. Write a C program to store elements in an array and calculate the sum and the average of elements stored?

#include<stdio.h>
#define MAX 50
void read(int a[MAX], int n);
void display(int a[MAX],int n);
void sumav(int a[MAX],int n);
int main()
{
int n, a[MAX];
printf("Enter array size\n");
scanf("%d",&n);
read(a,n);
display(a,n);
sumav(a,n);
return 0;
}
//Chetan Shidling
void read(int a[MAX], int n)
{
int i;
printf("Enter the array elements\n");
for(i=0;i<n;i++)
scanf("%d\n",&a[i]);
}
void display(int a[MAX],int n)
{
int i;
printf("Array elements are\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
//CS Electrical & Electronics
void sumav(int a[MAX],int n)
{
int i;
float avg, res=0;
for(i=0;i<n;i++)
{
res=res+a[i];
}
avg=res/n;
printf("Sum=%f\n",res);
printf("Average=%f\n",avg);
}

Output:

Enter array size
4
Enter the array elements
33
4
23
1
Array elements are
33
4
23
1
Sum=61.000000
Average=15.250000

09. Write a C program to store elements in the two-dimensional array (3 * 3 Matrix)?

#include<stdio.h>
int main()
{
int mat[3][3],i,j,sum=0;
printf("Enter elements for the matrix 3x3\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d\n",&mat[i][j]);
}
}
//Chetan Shidling
printf("matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("%d\t",mat[i][j]);
}
}
printf("\n");
return 0;
}
//CS Electrical & Electronics

Output:

Enter elements for the matrix 3×3
2
3
4
3
1
5
6
3
5
matrix is
2              3              4             
3              1              5             
6              3              5             

10. Write a C program to store elements in the two-dimensional array and add all elements of the array?

#include<stdio.h>
int main()
{
int mat[3][3],i,j,sum=0;
printf("Enter elements for the matrix 3x3\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat[i][j]);
sum=sum+mat[i][j];
}
}
printf("\nmatrix is");
//Chetan Shidling
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("%d\t",mat[i][j]);
}
}
printf("\n");
printf("sum of matrix is %d\n",sum);
return 0;
}
//CS Electrical & Electronics

Output:

Enter elements for the matrix 3×3
2
3
4
3
5 
1
4
7
3
matrix is
2              3              4             
3              5              1             
4              7              3             
sum of matrix is 32

11. Write a simple C program to perform addition?

#include<stdio.h>
int main()
{
                int n1, n2, result;
                printf("Enter two numbers\n");
                scanf("%d%d", &n1, &n2);
                result = n1 + n2;
                printf("sum = %d\n", result);
                return 0;             
}
//Chetan Shidling
//CS Electrical & Electronics

Output:

Enter two numbers
2
3
sum = 5

12. Write a C program to perform the binary operation using a switch statement?

#include<stdio.h>
int main()
{
                int n1, n2, ch, res;
                printf("1.Add\n2.Subtraction\n3.Multiplication\n4.Division\n5.Modulus\n");
                scanf("%d", &ch);
                printf("enter two numbers\n");
                scanf("%d%d",&n1, &n2);
                switch (ch)
{
                case 1:
                                res=n1+n2;
                                printf("sum=%d\n",res);
                                break;
                case 2:
                                res=n1-n2;
                                printf("Subtraction=%d\n",res);
                                break;
                case 3:
                                res=n1*n2;
                                printf("Multiplication=%d\n",res);
                                break;
                case 4:
                                if(n2==0)
                                printf("division is not possiblen");
                                else
                                {
                                res=n1/n2;
                                printf("Division=%d\n",res);
                                }
                                break;
                case 5:
                                res=n1%n2;
                                printf("Modulus=%d\n",res);
                                break;
                default:
                                printf("Invalid optionn");
                                break;
}
return 0;
}

Output:

1.Add
2.Subtraction
3.Multiplication
4.Division
5.Modulus
2
enter two numbers
3
1
Subtraction=2

13. Write a C program to perform the binary operation?

#include<stdio.h>
int main()
{
                int n1, n2, add, sub, mul, di, mod;
                printf("Enter two numbers\n");
                scanf("%d%d", &n1, &n2);
                add = n1 + n2;
                sub = n1 - n2;
                mul = n1 * n2;
                di = n1 / n2;
                mod = n1 % n2;
//Chetan Shidling
                printf("addition = %d\n", add);
                printf("subtraction = %d\n", sub);
                printf("multiplication = %d\n", mul);
                printf("division = %d\n", di);
                printf("modulus = %d\n", mod);
                return 0;             
}

Output:

Enter two numbers
2
3
addition = 5
subtraction = -1
multiplication = 6
division = 0
modulus = 2

14. Write a C program to perform a bitwise operation?

#include<stdio.h>
int main()
{
                int n1, n2, and, or, exor, ls, rs;
                printf("Enter 2 no’s\n");
                scanf("%d%d", &n1, &n2);
                and=n1&n2;
                or=n1|n2;
                exor=n1^n2;
                ls=n1<<n2;
                rs=n1>>n2;
                printf("After Swapping\n");
                printf("AND=%d\n",and);
                printf("OR=%d\n",or);
                printf("EXOR=%d\n",exor);
                printf("LEFT SHIFT=%d\n",ls);
                printf("RIGHT SHIFT=%d\n",rs);
                return 0;
}
//Chetan Shidling
//CS Electrical & Electronics

Output:

Enter 2 no’s
5
8
After Swapping
AND=0
OR=13
EXOR=13
LEFT SHIFT=1280
RIGHT SHIFT=0
Enter 2 no’s
4
4
After Swapping
AND=4
OR=4
EXOR=0
LEFT SHIFT=64
RIGHT SHIFT=0

15. Write a C program to give a bonus based on experience?

#include<stdio.h>
int main()
{
                int bs;
                float bonus, exp, tmnt;
                printf("enter salary and experience\n");
                scanf("%d",&bs);
                scanf("%f",&exp);
               
                if(exp>=5.0 && exp<=7.0)
                {
                bonus=(bs*(10.0/100.0));
                tmnt=bonus+bs;
                printf("Total amount = %f\n",tmnt);
                }
                else if(exp>=8.0 && exp<=10.0)
                {
                bonus=(bs*(20.0/100.0));
                tmnt=bonus+bs;
                printf("Total amount = %f\n",tmnt);
                }
                else
                {
                bonus=(bs*(30.0/100.0));
                tmnt=bonus+bs;
                printf("Total amount = %f\n",tmnt);
                }
return 0;
}
//CS Electrical & Electronics

Output:

enter salary and experience
23000
6
Total amount = 25300.000000

16. Write a C program to print buzz if the number is divisible by 5 and print the car if the number is divisible by 10?

#include<stdio.h>
int main()
{
                int n;
                printf("Enter number\n");
                scanf("%d",&n);                                              
                {
                if(n%10==0)
                printf("car\n",n);
                else if(n%5==0)
                printf("buzz\n",n);
                else
                printf("%d\n",n);                                            
                }
//Chetan Shidling
return 0;
}

Output:

enter number
20
Car

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

#include<stdio.h>
int main()
{
   int n,m;
   printf("Enter number\n");
   scanf("%d",&n);
   if(n%2==0)
   {
   printf("The number is even\n");
   }
   else
   {
   printf("The number is odd\n");
   }
   printf("Thank you\n");
return 0;
}

Output:

enter number
6
the number is even
thank you

18. Write a C program to compare two numbers?

#include<stdio.h>
int main()
{
   int n,m;
   printf("enter numbers m, n\n");
   scanf("%d%d",&m,&n);
   if(n<m)
   {
   printf("%d is smallest among two\n",n);
   }
   else
   {
   printf("%d is smallest among two\n",m);
   }
   printf("thank you\n");
//CS Electrical & Electronics
return 0;
}

Output:

enter numbers m, n
2
4
2 is smallest among two
thank you

19. Write a C program to convert binary value to decimal value?

#include<stdio.h>
int bintodec(int n1);
int main()
{
int n1,res;
printf("Enter the binary number(1s and 0s)\n");
scanf("%d",&n1);
res=bintodec(n1);
printf("Coverted Equivalent decimal = %d\n",res);
return 0;
}
//Chetan Shidling
int bintodec(int n1)
{
int dec=0,base=1,rem;
while(n1>0)
{
rem=n1%10;
dec=dec+(rem*base);
n1=n1/10;
base=base*2;
}
return dec;
}

Output:

enter the binary number(1s and 0s)
0110
Converted Equivalent decimal = 6

20. Write a C program to convert decimal value to binary value?

#include<stdio.h>
int dectobin(int dec);
int main()
{
int dec,res;
printf("Enter the decimal number\n");
scanf("%d",&dec);
res=dectobin(dec);
printf("Coverted Equivalent binary = %d\n",res);
return 0;
}
//CS Electrical & Electronics
int dectobin(int dec)
{
if(dec==0)
return 0;
else
{
return((dec%2)+(10*dectobin(dec/2)));
}
}

Output:

Output:
enter the decimal number
8
Coverted Equivalent binary = 1000

21. Write a C program for palindrome?

#include<stdio.h>
int pal(int num1);
int main()
{
int num1,rev,temp;
printf("Enter the number\n");
scanf("%d",&num1);
temp=num1;
rev=pal(num1);
if(rev==temp)
printf("The entered no. is palindrome\n");
else
{
printf("The entered no. is not a palindrome\n");
}
return 0;
}
//CS Electrical & Electronics
int pal(int num1)
{
int rem,rev=0,num;
do
{
rem=num1%10;
rev=(rev*10)+rem;
num1=num1/10;
}
while(num1!=0);
{
return rev;
}
}

Output:

Enter the number
121
The entered no. is palindrome
enter the number
425
The entered no. is not a palindrome

22. Write a C program to find the second largest number among the three numbers?

#include<stdio.h>          
int lar(int n1,int n2,int n3);
int main()
{
int a,b,c;
printf("Enter 3 no’s to find 2nd largest among\n");
scanf("%d%d%d",&a,&b,&c);
lar(a,b,c);
return 0;
}
int lar(int n1,int n2,int n3)
{
if(n1>n2)
{
     if(n1>n3)
     {
     printf("%d is the second largest among three\n",n3);
     }
     else
     {
     printf("%d is the second largest among three\n",n1);
     }
}
else if (n2>n3)
{
       if(n2>n1)
       {
       printf("%d is the second largest among three\n",n1);
       }
       else
       {
        printf("%d is the second largest among three\n",n2);
        }
}
else if (n3>n1)
{
        if(n3>n2)
        {
        printf("%d is the second largest among three\n",n2);
        }
        else
        {
        printf("%d is the second largest among three\n",n3);
        }
}
return 0;
}

Output:

Enter 3 no’s to find 2nd largest among
89
105
74
89 is the second largest among three

23. Write a C program to find the second smallest number among the three numbers?

#include<stdio.h>          
int lar(int n1,int n2,int n3);
int main()
{
int a,b,c;
printf("Enter 3 no’s to find 2nd smallest among\n");
scanf("%d%d%d",&a,&b,&c);
lar(a,b,c);
return 0;
}
int lar(int n1,int n2,int n3)
{
if(n1>n2)
{
     if(n1<n3)
     {
     printf("%d is the second smallest among three\n",n1);
     }
     else
    {
     printf("%d is the second smallest among three\n",n3);
     }
}
else if (n2>n3)
{
     if(n2<n1)
     {
     printf("%d is the second smallest among three\n",n2);
     }
     else
     {
     printf("%d is the second smallest among three\n",n1);
     }
}
else if (n3>n1)
{
     if(n3<n2)
     {
     printf("%d is the second smallest among three\n",n3);
     }
     else
     {
     printf("%d is the second smallest among three\n",n2);
     }
}
return 0;
}

Output:

Enter 3 no’s to find 2nd smallest among
30
10
20
20 is the second smallest among three

24. C Program to print 1 to 10 using for loop?

#include<stdio.h>
int main()
{
int i;
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}
return 0;
}

Output:

1
2
3
4
5
6
7
8
9
10

25. C Program to print number from 100 to 1 using for loop?

#include<stdio.h>
int main()
{
int i;
for(i=100;i>=1;i--)
{
printf("%d\n",i);
}
return 0;
}

Output:

100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1

26. C program to print any table using for loop?

#include<stdio.h>
int main()
{
int i,n;
printf("enter number");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf("%d*%d=%d\n",n,i,n*i);
}
return 0;
}

Output:

Enter number4
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=28
4*8=32
4*9=36
4*10=40

27. C program to print Fibonacci series using for loop?

#include<stdio.h>
int main()
{
int i,n,f1,f2,f3;
printf("Enter number\n");
scanf("%d",&n);
f1=0;
f2=1;
printf("%d\n%d\n",f1,f2);
for(i=1;i<=n;i++)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
return 0;
}
//CS Electrical and Electronics

Output:

Enter number8
0
1
1
2
3
5
8
13
21
34

28. Perform Niven or Harshad number in C programming?

#include <stdio.h>
int main()
{
int n, digit, sum=0, result=0, num;
printf(“Enter the number”);
scanf(“%d”, & n);
num = n;
while(num !=0)
{
digit = num % 10;
sum = sum + digit;
num = num/10;
}

result= n / sum;
printf(“Result is %d”, result);
return 0;
}

Output:

Enter the number 22
Result is 5

I hope this article may help you all a lot. Thank you for reading. If you have any doubts related to this article “C language interview questions”, then comment below.

Also, read:

Author Profile

CS Electrical And ElectronicsChetu
Interest's ~ Engineering | Entrepreneurship | Politics | History | Travelling | Content Writing | Technology | Cooking
Share Now

CS Electrical And Electronics

Interest's ~ Engineering | Entrepreneurship | Politics | History | Travelling | Content Writing | Technology | Cooking

Comments are closed.