Programming for Problem Solving Sem 2
GOVERNMENT COLLEGE OF ENGINEERING & CERAMIC TECHNOLOGY
AN AUTONOMOUS INSTITUTE
AFFILIATED TO MAKAUT (FORMERLY KNOWN AS WBUT)
Theory / B.Tech/CS/ SEM -II/ /Paper Code- : ES(CS/IT) 204
QUESTION BANK FOR Programming for Problem Solving
Course Outcomes (COs)
Course Outcomes
(COs)
1 To formulate simple algorithms for arithmetic and logical problems.
2 To translate the algorithms to programs (in C language).
3 To test and execute the programs and correct syntax and logical errors
Acronyms:
CD: Cognitive Domain
R: Remember
U: Understand
Ap: Apply
An: Analyze
E: Evaluate
C: Create
KD: Knowledge Domain
F: Factual
Con: Conceptual
P: Procedural
M: Metacognitive
QT: Question Type
O: Objective
S: Short Answer Type
E: Essay Type
N: Numerical type
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
Unit 1: Computer Fundamentals
1 With neat diagram briefly describe Von-Numan 4
architecture.
2 List some properties of a good algorithm. 4
3 Write the algorithm to find the greatest number among 3
three given numbers.
4 Write an algorithm to find the GCD. 3
5 Draw the flow-chart to find the Fibonacci series up to n 4
terms.
6 In a number system there are three symbols {η, Ψ, ω} 4
in ascending order of their
weightages, then, -
a) what is the decimal equivalent of the number ωηω?
b) what is the binary equivalent of the number Ψη?
7 Perform the following conversions, - 3
mark
s
each
8 What is the primitive data type. 1
9 Write an algorithm to swap two variables without using 3
a third variable and without using any mathematical
operator.
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
10 Write an algorithm to find whether a year is a leap year 3
or not.
11 (24F)16=(?)8 1
12 Within main, return expr statement is equivalent to 1
________
(a) abort(expr) (b) exit(expr) (c) ferror(expr) (d)
none of the mentioned
Unit 2 : Arithmetic expressions and precedence
1 1
What will be the data type of following operation?
(float)a * (int)b / (long)c * (double)d
2 1
What will be the output of the below program
#include <stdio.h>
int main()
printf("%d", printf("%d", printf("%d", printf("%s",
"Welcome to C Programming Class"))));
return (0);
}
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
3
What will be the output of the below code snippet?
#include <stdio.h>
int main()
int a = 15, b;
b = (a++) + (a++);
a = (b++) + (++b);
printf("a=%d b=%d", a, b);
return (0);
4 Write a short note on type conversion in C language. 4
5 Write a C program to demonstrate the size occupied by
the declared variables.
6 1
What will be the output of the below code snippet?
#include <stdio.h>
int main()
{
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
int a = 15, b;
b = (a++) + (a++);
a = (b++) + (b++);
printf("a=%d b=%d", a, b);
return (0);
7 1
What will be the output of the program
#include<stdio.h>
void main()
double number = 7.89;
printf("%d", sizeof(number));
8 1
What will be the output of the program
#include<stdio.h>
void main()
{
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
printf("%d", sizeof("program"));
9 Write a C program to swap two variables without using a 3
third variable.
10 1
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = -5;
i = i / 3;
printf("%d\n", i);
return 0;
}
11 1
What will be the output of the following C code?
#include <stdio.h>
int main()
int i = 0, k;
label: printf("%d", i);
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
if (i == 0)
goto label;
}
12 Write a program in C to count the number of 1s in the 4
binary representation of a given integer.
13 Write a C program to swap two numbers using bitwise 4
XOR (without using a third variable)
14 Write a program to check if a number is a power of 2 4
using bitwise operators.
15 Given two integers, write a program to find the number of 4
different bits between them.
Unit 3 : Conditional Branching and Loops
1 Write a C Program to find the GCD of two numbers. 3
2 Write a C Program to decide whether a given (taken as 3
input) number is odd or even
3 Write a C Program to decide whether a given (taken as 3
input) number is prime or not
4 Write a C program to check the value of your marks (as 3
user input, in the scale of 100) and assigns the grade as
output based on your grading system
5 1
What is the output of the following program?
#include < stdio.h >
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
int main()
int a=1;
switch(a)
{
printf("GATE-CSE");
case 0: printf("Zero");
case 1: printf("One");
default: printf("None");
}
return 0;
6 4
Write a C Program to print the following pattern
7 4
Write a C Program to print the following pattern
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
8 1
What is the output of the following program?
#include<stdio.h>
void main()
int colour = 2;
switch (colour) {
case 0:
printf("Black"); break;
case 1:
printf("Red");
case 2:
printf("Aqua"); break;
case 3:
printf("Green"); break;
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
default:
printf("Other");
}
9 1
Write the output of the below program:
#include<stdio.h>
void main()
int i = 10;
static int x = i;
if (x == i)
printf("equal");
else if (x < i)))
printf("less than");
else
printf("greater than");
}
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
10 1
Write the output of the below program:
#include <stdio.h>
int main() {
int i;s
for (i = 0; ; i++) {
printf("%d\n", i);
return 0;
11 3
Write a C program to accept a year as user input and
check whether this year is leap year or not. Show the
message accordingly. (Note: Use appropriate variable
names and write comment in each line of code for
understanding)
12 1
What will be the output of the following program, in case
of any error also mention the reason?
int main(void)
main();
return -1;
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
13 1
How many iterations are needed to search an element in
a sorted array of n elements in an average case
scenario?
14 Write a C program to print Pascal’s Triangle in below pattern 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
15 Write a C program to print following Fibonacci Triangle
1 1
2 3 5
8 13 21 34
16 3
Write a C program to check whether a given number is
an Armstrong number. Number is given as user input.
(Hint: Armstrong number is a number that is equal to
the sum of its own digits each raised to the power of
the number of digits.
17 Write a C program to print the following triangle 3
pattern using a loop.
A
A B
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
A B C
18 3
Write a C program to reverse the digits of an input
number. Print the reversed number.
19 3
Write a C program to print an input number in words.
20 Which loop is commonly used to traverse an array? 1
a) switch
b) for
c) goto
d) do-while
21 Write a C program to print the multiplication table of a 4
number entered by the user (up to 10 terms).
22 Write a program to check whether a number is a prime 4
number using a loop.
23 Write a program to print all numbers from 1 to 100 that 4s
are divisible by both 3 and 5 using a for loop.
Unit 4 : Arrays
1 3
Write a C program to initialize an array of floating point
number and find the average of the elements in
the array.
2 4
Write a C program to initialize an array of floating point
numbers and sort the elements in the array in
descending order.
Sl Question Mark Q C ILO KD C HOT Reso
s T O D s/LO urce
Ts s&
Hints
3 4
Write a C program to initialize an array of floating point
numbers and sort the elements in the array in
ascending order
4 1
What is the index of the first element in a C array?(a)
-1 (b) 0 (c) 1 (d) depends on compiler
5 What will be the output of the following code snippet? 1
main()
{
int a[3] = {1, 2};
printf("%d", a[2]);
}
(a) 0 (b) 1 (c) 2 (d) garbage value
6 Which function is used to find the length of a statically 1
declared array in C?
a) length()
b) size()
c) sizeof(arr)/sizeof(arr[0])
d) len()
7 Which of the following is a correct way to initialize an 1
array?
a) int arr = {1, 2, 3};
b) int arr[] = {1, 2, 3};
c) int arr[3] = 1, 2, 3;
d) array arr[3] = {1, 2, 3};
8 Write a C program to search for a given element in an 3
array of 10 elements.
9 Write a C program to print only the duplicate elements in 3
an array.
10 Write a C program to merge two arrays into a third array. 4