0% found this document useful (0 votes)
8 views5 pages

C Programming Question Bank and Solutions

Uploaded by

shrey1234yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

C Programming Question Bank and Solutions

Uploaded by

shrey1234yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question Bank

Questions for 2 Marks :

1. Write a C program to check whether a given year is a leap year or not.


2. Write a C program to input a character and check the character is alphabet, digit or special
character.
3. Consider the following program and explain its output.

#include<stdio.h>
int main()
{
for(printf("Hello");printf("Vinay")-printf("Agrawal"); printf("From"))
{
printf("SUA");
}
}

4. Consider the following program and explain its output.

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

5. Explain what a loop is in C programming and apply your understanding to list and
describe its different types with syntax.
6. Explain the similarity and difference between if else if ladder and switch case.
7. Analyse the problem and write a C program to find the sum of all elements of a 2D
array.
8. Write a C program to input a 2D array and print its transpose.
9. Consider the following C program and explain its output.

#include<stdio.h>
int main()
{
int A[2][3] = {2,0,1,1,0,2};
printf("%lu %d", sizeof(A), A[A[0][2]][A[1][1]]);
}
10. Consider the following C program and explain its output.

#include<stdio.h>

int main()

int a[5] = {5, 1, 15, 20, 25};

int i, j, m;

i = ++a[1];

j = a[1]++;

m = a[i++];

printf("%d, %d, %d", i, j, m);

Questions for 5 marks:

11. Write a MENU-driven C program to perform basic arithmetic operations (+, -, *, /, %)


on two integer numbers according to the choice entered by the user, using a switch-
case statement.
12. Write a program to input a character and convert it into uppercase if its in lowercase and vice
versa.
13. Consider the following C program:

#include<stdio.h>
int main()
{
int x = 2;
switch(x)
{
case 1: printf("Hare\n");
break;
case 2: printf("Krishna\n");
case 3: printf("Hare\n");
default: printf("Ram\n");
}
}
Apply your understanding of the switch-case statement and explain the output of the
above program.

14. Consider the following C program and explain its output.

#include <stdio.h>
int main()
{
int i = 3;
switch (i)
{
case 0+1: printf("Geeks");
break;
case 1+2: printf("Quiz");
break;
default: printf("GeeksQuiz");
}
return 0;
}
15. Write a C program to check whether a given number is prime or not. Explain the logic
used in the program to determine the result. A number is prime if it have exactly 2
natural numbers as factors.
16. Write a C program to check whether a given number is strong or not. Explain the
logic used in the program to determine the result. A strong number is a number where
the sum of factorial of every digit is equals to the number itself.

Ex : 145 is a strong number

1! + 4! + 5! = 145

17. (a) What is a function in C programming?


(b) Write any two advantages of using functions in a program.
(c) Explain the different parameter passing techniques used in functions with suitable
examples.

18. Write a C program to print the n terms of Fibonacci series using recursion.

19. Apply the concept of Bubble Sort to analyse and sort the given array of 5 elements:
8, 2, 7, 1, 5

20. Write a program to input an array and search a particular element.

21. Consider the following C program:

#include<stdio.h>
int main()
{
int A[3][2] = {5,2,9,6,8,7};
printf("%u %u %u\n", A[1]+2, A+5, &A+3);
}

Assuming the base address of the array A is 1000 and the size of an integer is 4 bytes,
analyse the program and determine the output of the above code.

22. Consider the following C program and explain its output.


#include<stdio.h>
int main()
{
int i,j;
int A[][3] = {7,1,4,8,2,9,5};
for(i=0;i<sizeof(A)/sizeof(A[0]);i++)
{
for(j=0;j<sizeof(A[0])/sizeof(A[0][0]);j++)
printf(“%d\t”,A[i][j]);
printf(“\n”);
}
}

23. Consider the following C program:

#include<stdio.h>
int main()
{
int x = 5;
if(x < 100)
x%=7;
else if(x == 35)
x>>=2;
else;
x -= 2;
printf("%d", x);
}

(a) Apply your understanding of conditional statements and determine the output of
the above program.
(b) Explain the difference between the break and continue statements in C
programming with the help of example programs.

24. What will be the output of the following codes.


a.) #include <stdio.h>
int main()
{
if('Z'<'z')
printf("I have robbed and killed..");
else
printf("Until my evil purse was filled..");
return 0;
}
b.) #include <stdio.h>
int main()
{
int x=100;
if(!!x)
printf("x= %d",!x);
else
printf("x= %d",x);
return 0;
}

25. Write a C program to find the maximum and minimum elements in an array. Analyse
the logic used in your program and explain how comparisons are made to determine
the largest and smallest values.

26. Write a c program to input an array of n elements , traverse it from start to end and
delete all the elements of array which are Armstrong number and print the updated
array. An Armstrong number is a number where the sum of power of every digit with
its digit count is equal to the number itself.

Ex: 153 is an Armstrong number as it has 3 digits.

13 + 53+ 33 = 153

You might also like