Академический Документы
Профессиональный Документы
Культура Документы
QUESTION BANK
BATCH : 2007-2010
Unit III
Q.2 Define and describe the constants used in C with statements and
appropriate examples.
Q.3 Describe the different types of variables and their declaration with example
of each.
Q.4 Find errors (if any) and explain why for the following statements:
(i) Int X;
(iii) double = P, q
(iv) exponent alpha, beta;
(v) m, n, z : INTEGER
(vi) long int m; count;
(vii) long float temp;
Q.5 Draw the basic structure of C programs. Explain its different sections in brief with
suitable examples.
Q.6 Write a program to find the area and perimeter of a rectangle using the formulae:
area = breadth*height
Q.7 Write a program to find theorem and perimeter of a triangle from the lengths of its 3 sides
perimeter = a + b + c
area =√ s(s-a) (s-b) (s-c)
where s =( a + b + c)/2
note that triangle can be formed if a < b+c and b < a+c and c< a+b.
Q. 8 Identify integer type variable among specifiers ------ char, double, long and the long
double.
Q.10 Give the range of maximum/ minimum values with number of storage-bytes in char, int,
Long, float, double, long double, unsigned char, unsigned int, and unsigned double types
of variables in C/C++.
Q.11 Explain automatic type conversions among char, int, long, float and double data types in
C/C++
B. If a five-digit number is input through the keyboard, write a program to calculate the sum
of its digits. (Hint: Use the modulus operator ‘%’)
C. If the marks obtained by a student in five different subjects are input through the
keyboard, find out the aggregate marks and percentage marks obtained by the student.
Assume that the maximum marks that can be obtained by a student in each subject is 100.
Q.9 Objective type Questions:
(e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;
C. C can be used on
(1) An Editor
(2) A compiler
Unit IV
Q.2 Describe how branching and looping is done in C with proper example.
Q.3 Find errors (if any) and explain why for the following statements:
i) scanf(“%c%f%d”, city ,&price,&year);
ii) printf(“a=%d b=%fn c=%c”\n,a,b,c);
iii) if(code>1);
a=b+c
else
a=0.
iv) name[] = getchar();
v) putchar(‘answer\n’);
vi) for( i=1; i<R; ++i )
}
printf(“*”);
}
vii) scanf(“%c %d %d ”, *code, &count , Root);
Q.6 Write a program to print multiplication table from 1 to 10 using do-while loop.
Q. 7 List the different data types in C language, their sizes, and their ranges on a lb bit
machine.
Q.8 Write a program to solve a quadratic equation ax2 + bx + c = 0 (a ≠ 0) . Tackle the 3 cases
d=0, d<0, d>0 (d = discriminant = b2 = b2 – 4 ac) series rately with suitable remarks. The
roots are given by:
- b ± √ b2 – 4ac
_____________
2a
A. Any integer is input through the keyboard. Write a program to find out whether it
is an odd number or even number.
B. Any year is input through the keyboard. Write a program to determine whether
the year is a leap year or not. (Hint: Use the % (modulus) operator)
C. If the ages of Ram, Shyam and Ajay are input through the keyboard, write a
program to determine the youngest of the three.
D. Write a program to enter the numbers till the user wants and at the end it should
display the count of positive, negative and zeros entered.
E. Write a program to print all prime numbers from 1 to 300. (Hint: Use nested
loops, break and continue)
F. Write a program to produce the following output:
G. Write a program which to find the grace marks for a student using switch. The
user should enter the class obtained by the student and the number of subjects he
has failed in.
− If the student gets first class and the number of subjects he failed in is greater than
3, then he does not get any grace. If the number of subjects he failed in is less than or
equal to 3 then the grace is of 5 marks per subject.
− If the student gets second class and the number of subjects he failed in is greater
than 2, then he does not get any grace. If the number of subjects he failed in is less
than or equal to 2 then the grace is of 4 marks per subject.
− If the student gets third class and the number of subjects he failed in is greater than
1, then he does not get any grace. If the number of subjects he failed in is equal to 1
then the grace is of 5 marks per subject
H. Implement the Selection Sort, Bubble Sort and Insertion sort algorithms on a set
of 25 numbers.
A. main( ) {
int a = 300, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "\n%d %d", b, c ) ;
}
B. main( ) {
int k = 35 ;
printf ( "\n%d %d %d", k == 35, k = 50, k > 40 ) ;
}
C. main( )
{
int i = 65 ;
char j = ‘A’ ;
if ( i == j )
printf ( “C is WOW” ) ;
else
printf( "C is a headache" ) ;
}
D. main( )
{
int a = 5, b, c ;
b = a = 15 ;
c = a < 15 ;
printf ( "\na = %d b = %d c = %d", a, b, c ) ;
}
E. main( )
{
int x = 15 ;
printf ( "\n%d %d %d", x != 15, x = 20, x < 30 ) ;
}
F. main( ) {
int j ;
while ( j <= 10 )
{
printf ( "\n%d", j ) ;
j=j+1;
}
}
G. main( )
{
int i = 1 ;
while ( i <= 10 ) ;
{
printf ( "\n%d", i ) ;
i++ ;
}
}
H. main( )
{
int j ;
while ( j <= 10 )
{
printf ( "\n%d", j ) ;
j=j+1;
}
}
I. main( ) {
int i = 1, j = 1 ;
for ( ; ; )
{
if ( i > 5 )
break ;
else
j += i ;
printf ( "\n%d", j ) ;
i += j ;
}
}
J. main( ) {
int c = 3 ;
switch ( c )
{
case 'v' :
printf ( "I am in case v \n" ) ;
break ;
case 3 :
printf ( "I am in case 3 \n" ) ;
break ;
case 12 :
printf ( "I am in case 12 \n" ) ;
break ;
default :
printf ( "I am in default \n" ) ;
}
Unit V
Q.1 Write a program for finding the values of mean, standard deviation and variance of n
fractional numbers using an array for storing numbers:
n
(i) mean = Σ xi
i=1
n
Σ xi
i=1
(ii) s.d. = √ n
_
(iii) where x = mean.
(iv) Variance = (s.d.)2
Q.2 Write a program for entering the elements of a matrix with a desired number of
rows and columns ( < =10).
Print the matrix and its
Q.1 Write declaration statement for one-dimensional, two- dimensional and multi-
dimensional arrays.
Q.2 Define and describe the character string in C with declaration statement. What are
the operations on character strings in C, explain with example.
Q.3 Describe:
i) Structure
ii) Arrays of structure
iii) Arrays with structures
iv) Pointers
v) structures with structures
Q.4 Write a program to sort ‘n’ numbers in descending order using array.
A. main( ) {
printf ( "\nOnly stupids use C?" ) ;
display( ) ;
}
display( )
{
printf ( "\nFools too use C!" ) ;
main( ) ;
}
C. main( )
{
int i = 45, c ;
c = multiply ( i * 1000 ) ;
printf ( "\n%d", c ) ;
}
check ( int ch )
{
if ( ch >= 40000 )
return ( ch / 10 ) ;
else
return ( 10 ) ;
}
D. main( ) {
void slogan( ) ;
int c = 5 ;
c = slogan( ) ;
printf ( "\n%d", c ) ;
}
void slogan( )
{
printf ( "\nOnly He men use C!" ) ;
}
E. main( ) {
struct gospel
{
int num ;
char mess1[50] ;
char mess2[50] ;
}m;
m.num = 1 ;
strcpy ( m.mess1, "If all that you have is hammer" ) ;
strcpy ( m.mess2, "Everything looks like a nail" ) ;
/* assume that the strucure is located at address 1004 */
printf ( "\n%u %u %u", &m.num, m.mess1, m.mess2 ) ;
}
F. struct gospel {
int num ;
char mess1[50] ;
char mess2[50] ;
} m1 = { 2, "If you are driven by success",
"make sure that it is a quality drive"
};
main( )
{
struct gospel m2, m3 ;
m2 = m1 ;
m3 = m2 ;
printf ( "\n%d %s %s", m1.num, m2.mess1, m3.mess2 ) ;
}
J. Write a program to add the contents of one file at the end of another.
K. Suppose a file contains student’s records with each record containing
name and age of a student. Write a program to read these records and display
them in sorted order by name.
L. How will you use the following program to
(a) − Copy the contents of one file into another.
(b) − Print a file on the printer.
(c) − Create a new file and add some text to it.
M. Write a program using command line arguments to search for a word
in a file and replace it with the specified word. The usage of the program is
shown below. C> change <old word> <new word> <filename>