Pps Unit Wise Questions
Pps Unit Wise Questions
Pps Unit Wise Questions
PRATICE QUESTIONS
SUBJECT: PROGRAMMIN FOR PROBLEM SOLVING
1 MARKS QUESTIONS
FILL IN THE BLANKS
UNIT-I (basics, if..else, switch)
1) Find the output:
main() [CO1/PO2]
{ int x=5;
printf(“%d”,printf(“%d%d”,x,x)); }
options:
a) 5 5 5
b) 5 5 1
c) 5 x x
d) 5 5 2
3) The given statement x=x+5; Its equivalent statement using += operator is: [CO1/PO2]
Options:
a) x+=5;
b) x+5;
c) x=5;
d) x= =5;
4) In C language, which library function checks whether the input value of the argument is an
alphabet or not. [CO1/PO2]
Options:
a) alpha()
b) isalpha()
c) alphabet()
d) chkalpha()
z=(x<y)+10;
printf(“%d”,z);
options:
a) 10
b) 1
c) 11
d) error
9) Given: [CO1/PO2]
int x,y,z,q;
x=10; y=5; z=3;
q=x>y>z;
printf(“%d”,q);
the output is :
options:
a) 1
b) 0
c) 10
d) 5
11) The format identifier ‘%i’ is also used for _____ data type? [CO1/PO2]
options
a) char
b) int
c) float
d) double
else
printf("x and y are not equal");
return 0;
}
Options:
a) x and y are equal
b) Compile Error
c) Run Time Error
d) x and y are not equal
Options:
a) 100,300,400
b) 100,200,400
c) 500,200,400
d) 100,300,300
15) Find the output from options given, when we execute the below statements:[CO1/PO2]
int a,b;
float d;
a=10; b=5;
d=(float)b/a;
printf(“ %d, %d, %f”,a,b,d);
options:
a) 10, 5, 0
b) Error
c) 10, 5, 0.500000
d) None of the above
Options:
a) size =1
b) size =2
c) size =4
d) Error
a=SUM/SUM;
printf(“%d”,a);
}
Options:
a) 1
b) 21
c) 20
d) Error
18) Find the output from below options when we execute the below statements: [CO1/PO2]
int a,b,c,d,e;
a=10; b=20; c=15; d=25;
e=(a>b)? c : d ;
e=(e>a)? 1 : 0;
printf(“%d”,e);
options:
a) 0
b) 1
c) false
d) true
19) Find the output of below statement in the given options: [CO1/PO2]
printf(“santosh\b\b\bilata\nare you\?”);
options:
a) Santosh ilata
are you?
b) santilata
are you?
c) Santosh ilata
are you”
d) santilata
are you”
Options:
a) 128
b) Garbage value
c) Error
d) 0
#include <stdio.h>
#define EVEN 0
#define ODD 1
int main()
{
int i = 3;
switch (i & 1)
Page No. 5
{
case EVEN: printf("Even");
break;
case ODD: printf("Odd");
break;
default: printf("Default");
}
return 0;
}
Options:
a) Even
b) Odd
c) Default
d) compile-time error
2) The keyword used to transfer control from a function back to the calling function is:
Options: [CO2/PO1]
a) return
b) exit()
c) break
d) continue
Options:
a) In while loop after while loop
b) After while loop
c) Compile time error
d) Infinite loop
Options:
Page No. 6
a) infinite loop
b) hi
c) error
d) none of the above
Options:
a) C MarathonC Marathon
b) E Marathon
c) Marathon
d) error
10) What will happen if in a C program you assign a value to an array element whose subscript
exceeds the size of array?
Options: [CO2/PO1]
a) The element will be set to 0.
b) The compiler would report an error.
c) The program may crash if some important data gets overwritten.
d) The array size would appropriately grow.
1) If the two strings are identical, then strcmp() function returns: [CO3/PO1]
Options:
a) 0
b) 1
c) Equal
d) Identical
Options:
a) To reverse a string
b) To copy a string
c) To print a string
d) To join a string with other
void foo( );
int main( )
{
foo( );
return 0;
}
void foo( )
{
printf("2 ");
}
Options:
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Options:
a) hi
b) run time error
c) Nothing print
d) It varies
8) Any type of modification on the parameter inside the function will reflect in actual variable
value can be related to:
Options: [CO3/PO2]
a) call by value
b) call by reference
c) both of above
d) none of above
Options:
a) 0
b) 1
c) 2
d) 3
I) The maximum value a variable can hold depends upon its storage class.
II) By default all variables enjoy a static storage class.
options:
a) Only I is correct
b) Only II is correct
c) Both I & II are correct
d) Both I & II are incorrect
#include< stdio.h>
void fun()
{
fun();
return 0;
}
void fun()
{
auto int i = 1;
register char a = ‘D’;
static int p = 0;
printf(“%d %d %d”, i, a, p);
}
Page No. 9
options
a) 1 D 0
b) 1 0 0
c) 0 D 1
d) 1 68 0
Options:
a) Garbage value
b) 0 0
c) 1 0
d) 1 1
13) What will be the storage class of variable I in the code written below? [CO3/PO3]
#include< stdio.h>
int main()
{
int i = 10;
printf(“%d”, i);
return 0;
}
Options:
a) Automatic storage class
b) Extern storage class
c) Static storage class
d) Register storage class
14) Where will the space be allocated for an automatic storage class variable? [CO3/PO2]
Options:
a) In CPU register
b) In memory as well as in CPU register
c) In memory
d) On disk
#include< stdio.h>
int main()
{
int a=1;
static char j = ‘E’;
printf(“%c”, ++j);
printf(“%d”, --a);
return 0;
}
Options:
a) E 2
Page No. 10
b) F 1
c) F Garbage
d) F 0
3) The memory allocation function which modifies the previous allocated space is:
Options: [CO4/PO1]
a)calloc()
b)malloc()
c)free()
d)realloc()
Options:
a) Hello
b) HelloWorld
c) World
d) None of these
Options:
a) to hold different data types
Page No. 11
Options:
a) calloc() takes a single argument while malloc() needs two arguments
b) malloc() takes a single argument while calloc() needs two arguments
c) malloc() initializes the allocated memory to ZERO
d) calloc() initializes the allocated memory to NULL
options:
a) stdlib.h
b) malloc.h
c) calloc.h
d) None of above
#include<stdio.h>
int main()
{
char str[] = "Nagpur";
str[0]='K';
printf("%s, ", str);
str = "Kanpur";
printf("%s", str+1);
return 0;
}
Options:
a) Kagpur,Kanpur
b) Nagpur,Kanpur
c) Kagpur,anpur
d) error
typedef struct p
{
int x, y;
}k;
int main()
{
struct p q = {1, 2};
k = p;
printf("%d\n", k.x);
}
Options:
a) Compile time error
b) 1
c)0
d) Depends on the standard
Page No. 12
options:
a) Does not create a new type
b) It merely adds a new name for some existing type.
c) Both a & b
d) None of the mentioned
options:
a) Another structure
b) Function
c) Array
d) None of the mentioned
10) Find the output when we execute the below statements: [CO1/PO2]
int x,y,z,a;
x=30;y=20;z=10;
a=x>y>z;
printf(“%d”,a);
11) Find the output when we execute the below statements: [CO1/PO2]
int y,z,a;
y=3; z=4;
a=y*=z/=2;
printf(“%d”,a);
12) Find the output when we execute the below statements: [CO1/PO2]
int a,b;
a=20;
b=a>>1;
printf(“%d %d”,a,b);
13) Find the output when we execute the below statements: [CO1/PO3]
int a,b,c,e;
a=10; b=20; c=30;
e=(a>b)|| (b<c) && (c==50);
printf (“%d”,e);
14) Find the output when we execute the below statements: [CO1/PO3]
int a,b,c,d,e;
a=100; b=50; c=30; d=0;
e=(a>=b>=c>=d);
Page No. 13
printf(“%d”,e);
15) what will be the output and why? [CO1/PO3]
#include<stdio.h>
void main()
{ int x,y; x=10; y=10;
if(x/x%x) printf(“It is summer”);
else printf(“it is rainy”);
}
16) what will be the output and why? [CO1/PO3]
#include<stdio.h>
void main()
{ int s;
s=(0= =0) ? 0 : 1 ;
if(!s) printf(“my land is beautiful”);
else printf(“my country is great”);
}
[CO2/PO2]
2) State the syntax of do..while loop? [CO2/PO1]
3) What is an array ? What are the types of it? How to initialize values to a 1D array during its
declaration. [CO2/PO2]
4) Write down the syntax and example of for statement. [CO2/PO2]
5) What is an infinite loop? [CO2/PO2]
6) How to interact with all the elements of a matrix using simple loop control statements?
[CO2/PO2]
7) State the difference between while and do..while [CO2/PO2]
8) Differentiate between a for loop and a while loop? What are it uses? [CO2/PO2]
9) Why is it necessary to give the size of an array in an array declaration? [CO2/PO1]
10) Define Conditional control structure and its types [CO2/PO1]
11) What is the use of break statement [CO2/PO1]
12) What is continue statement and why we use it ? [CO2/PO2]
13) Give out the syntax of for loop with an example. [CO2/PO2]
14) what will be the output and why? [CO2/PO3]
main()
{ int i,j;
i=0; j=400;
while(i<j) --j; ++i;
printf(“%d”, i – j );
}
15) what will be the output and why? [CO2/PO3]
main()
{ int K;
for(K=0; K<printf(“HELLO”); K++)
printf(“%d”,K);
}
16) what will be the output and why? [CO2/PO2]
main()
{ printf(“%c”, “abcdef”[4]); }
printf(“%d”,c);
}
LONG QUESTIONS:
5)
a. Explain briefly about the basic structure of a c program. [CO1/PO2]
b. Write down the syntax of else if ladder. State the difference between switch..case and
else if ladder. Write a program to input 3 unequal numbers and find the greatest using
switch..case. [CO1/PO2]
6)
a. Write down the syntax of else..if ladder. Write a program to input 3 co-efficient
values and find the real roots of a quadratic equation using else if ladder. [CO1/PO2]
b. Write down the syntax of conditional operator and Write a program to find the
greatest among 5 integers using conditional operators. [CO1/PO2]
7)
a. Write a program to accept arithmetic operator and two operands. Find the result as
per the operator symbol entered using else if ladder. [CO1/PO2]
Page No. 17
b. Write a program to input 4 unequal numbers and find the greatest using else if ladder.
[CO1/PO2]
8)
a. Write a program input a lowercase character and test it for vowel or not using
switch..case. [CO1/PO2]
b. Write a program to display weekday as per the digit given within(1 to 7), i.e: 1 –
Sunday, 2- Monday, 3-Tuesday etc. Use switch..case [CO1/PO2]
b. Write down the syntax of while, do..while and for statement. State the difference
between while and do..while using suitable example. [CO2/PO3]
5)
a. Explain how an array can be declared and initialized? Write a suitable program to
interact with 1-D array elements. [CO2/PO2]
b. Briefly explain the syntax of while, do..while and for statements using a suitable
example. [CO2/PO2]
6)
a. Write down the difference between Entry Controlled vs. Exit Control loop with
suitable example. Write a program to print Alphabets from ‘A’ to ‘Z’ using while.
[CO2/PO2]
b. Write a program to input a positive integer and its equivalent binary number using
loop. [CO2/PO2]
7)
a. Write a program to input elements into 4 × 4 matrix and find the principal diagonal.
[CO2/PO2]
b. Write a program to accept a number test whether it is palindrome or not. [CO2/PO3]
8)
a. Write a program to find the greatest common divisor of given two positive integers.
[CO2/PO2]
b. Write a program to input a positive number and test whether it is Armstrong number
or not. [CO2/PO3]
9)
a. Write a program to input a number and check whether it is prime or not. [CO2/PO3]
b. Write a program to input values into a 4X4 matrix and find the sum of its diagonal
elements. [CO2/PO2]
10)
a. Write a program print a series of numbers 1,4,9,16,25……n2 where n is given as
input. [CO2/PO3]
Page No. 18
b. Write a program to input values into a 4X4 matrix and display the transpose of it.
[CO2/PO2]
13)
a. Write a program to print the pyramid [CO2/PO3]
5
56
567
5678
56789
b. Write a program to find the factorial of a given +ve number using while. [CO2/PO3]
2)
a. What are the necessary statements for writing an UDF? What is the difference
between actual parameters and formal parameters? Explain with a suitable example.
[CO3/PO2]
b. What are the function categories ? Explain all the categories with suitable examples.
[CO3/PO2]
3)
a. What is a recursive function? How it is different from a iterative function? Write a
program to find the factorial of a given number using recursive function and also
using iterative function. [CO3/PO3]
b. Briefly explain all the storage classes and their characteristics. [CO3/PO2]
4)
a. Write a program to accept the string and count the number of vowels present in the
string. [CO3/PO3]
b. Write a program to test a string is palindrome or not without using string handling
functions. [CO3/PO2]
5)
a. Write a C program which contains three UDF’s namely add(), subtract() and
multiply(). Each function accepts two integers as their arguments and calculate and
return the results [CO2/PO3]
b. Write a program to accept two strings and check whether they are equal or not using
UDF. [CO3/PO2]
6)
a. Write a program to input values into two 4X4 matrices. Create an UDF which accepts
the two matrices and perform matrix addition. [CO3/PO2]
Page No. 19
9)
a. What is a pointer ? How a pointer can be used to navigate between memory locations
of 1D array and 2D array? Explain briefly with a suitable example. [CO4/PO3]
b. What is the advantage of a character pointer over a character array? Explain the terms:
array of pointers, pointe to pointer. [CO4/PO3]
10)
a. Explain the syntax and example on malloc(), calloc(), realloc(). Write a program to
allocate N integer memory and then input the numbers and find the average.
[CO4/PO3]
b. Write a program to create user defined function called swap having two integer pointers
as its arguments and it has no return value. Call this function using call-by-address.
[CO4/PO3]
11)
a. Write a program to input 10 integers into an array. Create an UDF which accepts the
base address of array and finds the sum of even numbers and sum of odd numbers
separately. [CO4/PO3]
b. Write a program to store N values using dynamic memory allocation. Then find largest
and smallest number present in it using UDFs MAX() and MIN(). [CO4/PO3]
12)
a. Write a program to store 11 cricket players’ details into an array of structure. The
structure having member’s player name, team name and batting average. Create an
UDF which displays the name of players whose batting average is >=30. [CO4/PO3]
b. Write a program to create a structure called SUBJECTS having members: rollno,
physics, chemistry, maths, total marks. Create a structure array to store 10 students
marks. Calculate the total marks of each student. [CO4/PO3]