Вы находитесь на странице: 1из 12

# DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

QUESTION BANK
BATCH : 2007-2010

## Semester/Branch : BE III /Electrical Engg.

Subject : Numerical Analysis and Computer Programming

Unit III

## Q.1 Differentiate between C and C++ Programming Language.

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;

## (ii) float letter, DIGIT.

(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:

## where breadth and height are in centimeters and can be in fraction.

Q.7 Write a program to find theorem and perimeter of a triangle from the lengths of its 3 sides

## a, b and c (in inches and can be in fraction) :

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.

## (iv) Library files in C/C++

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++

## A. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a

program to convert this temperature into Centigrade degrees.

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:

## (d) 3.14 * r * r * h = vol_of_cyl ;

(e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;

## (4) Martin Richards

C. C can be used on

(1) An Editor

(2) A compiler

## (3) An operating system

(4) None of the above

## Q.10 Theory Questions:

A. Draw the flowchart for a program to find roots of quadratic equations.
B. Give the basic structure of C program.
C. List all C operators along with their precedence and associativity.
D. What are the advantages of using C language over other languages?
E. How to swap two variables, without using temporary variable?

Unit IV

## Q.1 Describe logical operators in C briefly.

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();
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

## The imaginary roots should be printed in the form of a + ib and a – ib.

Q.9 The volumes of sphere, cone cylinder are given as:
(i) (4/3) πr3
(ii) (1/3) πr3 h
(iii) πr2 h

## respectively where r = radius in centimeters, h = height in centimeters, π = 3.14159. Both

r and h can be in fraction. Write a program using switch statement to calculate and print
the volumes with suitable remarks.

## Q.10 Write a program to:

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.

## Q.11. What would be the output of the following programs:

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" ) ;
}

## Q.12. Theory Questions:

A. Explain various jump statements in C with the help of example for each.

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.

## Q.5 What would be the output of the following programs:

A. main( ) {
printf ( "\nOnly stupids use C?" ) ;
display( ) ;
}
display( )
{
printf ( "\nFools too use C!" ) ;
main( ) ;
}

## B. main( ) { int i = 45, c ;

c = check ( i ) ;
printf ( "\n%d", c ) ;
}
check ( int ch )
{
if ( ch >= 45 )
return ( 100 ) ;
else
return ( 10 * 10 ) ;
}

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 ;
char mess2 ;
}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 ;
char mess2 ;
} 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 ) ;
}

## Q.6 Write a Program to (Use functions):

A. Write a function to calculate the factorial value of any integer
entered through the keyboard.
B. Any year is entered through the keyboard. Write a function to
determine whether the year is a leap year or not.

## C. A 5-digit positive integer is entered through the keyboard, write a

function to calculate sum of digits of the 5-digit number:

## D. Write a function which receives a float and an int from main( ),

finds the product of these two and returns the product which is printed
through main( ).

## E. Write a function that receives 5 integers and returns the sum,

average and standard deviation of these numbers. Call this function from
main( ) and print the results in main( ).
F. Write a general purpose function to convert any given year into its
roman equivalent.
G. Write a program that converts all lowercase characters in a given
string to its equivalent uppercase character.

## H. Write a program to sort a set of names stored in an array in

alphabetical order.

## I. Create a structure to specify data on students given below: Roll

number, Name, Department, Course, Year of joining
(a) Assume that there are not more than 450 students in
the collage.

## (b) Write a function to print names of all students who

joined in a particular year.

## (c) Write a function to print the data of a student whose

roll number is given.

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>

## Q.7 Theory Questions:

A. What is function prototype ? Explain the methods of passing arguments to
the function with example.
B. What is the difference between call by value and call by reference?
C. Define function. Discuss different categories of functions.
D. Explain structure within structure with the help of example.
E. Define string. Implement any five functions from string.h
F. Compare iterative and recursive function.

## G. What is the difference between fread and fscanf functions.

H. What is the difference between fwrite and fprintf.
I. What is pointer? Explain with the help of an example pointer to pointer.