Computer Programming - I
Computer Programming - I
com
N. B.:
(1) Attempt any three questions from each section including Question Nos. 1 and
6 which are compulsory questions.
(4) Use comments in programme and draw the flow-chart for each programme.
Logical correctness of the programme is must, syntax of the C-language must be
followed.
Section I
(d) Comment with suitable examples on the following operators in C in pointers &
and * .
i) x=15, y=10
x> = 8&y< = x
ii) 10 = 9 + 1;
(h) Give Range and Byte-width for following Data types in C any three :
2. (a) Write the C-Program to reverse the input 4-digit number. Draw the flow
chart. (Input number is integer type data type in C).(8)
(b) Modify the above C-Program to separate the individual digital 4-digit number
and display. Also get the sum of separated digits of same 4-digit number.
( Input No. 1234. Out put No. = 4321. separated digits 1, 2, 3, 4. sum = 4 + 3 + 2+
1- 10). (8)
i) String to be added.
i) || iv) !
ii) == v) &&
iii) ! =
4. (a) Explain the UNIX directory structure with suitable example. (4)
(b) Write the C-program to select 8s to display and to count total No of vowels
contained in User-Input string. (UseVowels(--)asfunction).Giveflow-chartalso. (8)
(c) Explain the variables in C for the following types, with suitable examples-
(4) i) extern modifier for variables. ii) static modifier for variables.
i) Show the use of > and > > redirection operators in UNIX. (4)
(b) Write the C-Program to display (EVEN) or [ ODD ] words for the input of
integer no. Using C-library functions. Draw the flow chart also. (8)
Compare the switch ( ) control. Statement with ladder. Control statement if-else-if.
(4)
Section II
x<<1
x<<3
x<<2
x<<1
x<<2
(d) Explain the arg C and arg V arguments of main ( ) function with suitable
examples.
i) Define the structure for the following examples, any one: i) Computer ii)
Teacher iii) Student.
7. (a) Explain and compare the while & do-while control loops of C language
with suitable examples. (8)
S sin (x)
C cos (x)
T Tan (x)
10. (a) Write the C-program to declare the structure for. COMPUTER configuration
having CPU-type, SDRAM-size, clock-speed, HDD-size, CDROM-Type (ROM, R/w),
CDROM-speed, Mouse-Type, Key-Board-Type, SVGA monitor make.
Read in the information for 50 COMPUTERS and list COMPUTER moving HDD-size
greater than 8GB. (8)
Section I
(a) Write a program that, given a number as input, prints its square, cube and
fourth power without doing any unnecessary calculations. (3)
(b) Write a program which reads and multiplies together 20 real numbers
(floating point numbers). * (3)
(c) Write a program to print a "4 times table" in the following form. (3)
1x4 = 4
2x4 = 8
3x4=12
4x4=16 etc.
(e) Write a program that reads a number greater than or equal to 1,000 from the
user where the user enters a comma in the input. Then print the number without a
coma. Here is the sample dialog. (5)
(a) Write a program that read two floating point numbers and tests whether they
are the same up to two decimal places. (4)
int n = 1;
float x = 0; float s;
do
S=1.0/(n*n);
x = x + s;
n++;
while (s>0.01);
(c) The Fibonacci sequence is defined by the following rule. The first two values
in the sequence are 1 and 1. Every subsequent value is the sum of the two values
preceding it. Write a program that prompts the user for n and prints the nth value of
the Fibonacci sequence. (4)
(d) Factoring of integers. Write a program that asks the user for an integer and
then prints out all its factors. For example, when the user enters 150, the program
should print (4)
3. (a) Write the program to compute the distance S fallen by an object in free
fall:
(b) Write a program to input data in to an array X (100), Compute the sum and
average. Then count the number of values of X greater than the average and the
number less than average. Print the values, The average, and the two counts. (8)
4. (a) One dimensional Array 'A [J]' has N elements and are in the memory of
the computer. Write a program segment which
i) Interchanges A[1] and A[2], only if A[1] > A[2], interchanges A[3] and A[4] only if
A[3] > A[4] and so on.
ii) Cyclically permutes the values of A so that A[2] contains the original value of
A[1], A[3] contains the original value of A[2] and so on, with A[1] containing the
original value of A[N]. (8)
(b) Write a program to read the names and total marks of a class of 50 students.
Arrange the data (names and marks) in descending order of total marks and print
the output with proper headings. (8)
Section II
7. A magic square is an n x n array of integers having the same value for the
entire row sums, column sums and sums of the two main diagonals. For Example:
(16)
492
357
816
In a 3 x 3 magic square with the sum of the rows, columns and diagonals equals to
15. The algorithm for forming an n x n magic square when n is as follows:
(b) As this is done, place the first number in the middle of the bottom row of the
array in position A (i, j).
(c) Place the rest of the number in position A (MOD (i, n) + 1, MOD(j,n) + 1},
unless a number is already there. In that case place it in position A(i-I,j).
(d) Repeat above step (step c.) until all the integers have been placed in the
array. Write a program that generates and prints magic squares ofsizes3,5,7,9,11,
13,15.
8 With the help of Functions for matrix multiplication and transpose write a program
to check the identity ( A X B )T = BT X AT where the order of matrix A is M X L and B
is L X N. Also write functions for matrix reading and matrix display. (16)
9. (a) What are recursive functions ? Explain with suitable examples. (8)
(b) Write a recursive function to find the GCD of two numbers using the following
Euclid's recursive algorithm. (8)
GCD(m, n) if n > m
GCD (m, n) = m if n = 0
10.(a) What is a union ? How does a union differ from a structure ? Explain with
suitable examples. (4)
www.techbirbal.com – Engineering the Future
www.techbirbal.com
(b) What is self referential structure ? For what kind of applications are self
referential structures useful? (4)
(c) Write a complete program to implement a structure for the following fields.
(8)
Name
Roll number
Date of Birth
Total marks
And also provide the provision to sort the list (Array of structures) on
any desired Field e.g. on Name, Roll number, Date of Birth etc.
N.B.:
Section I
1. (a) Explain basic data types supported by C-language along with their format
specifiers, memory requirements and Ranges. Give suitable example. (8)
(b) What are the identifiers ? State whether the following identifiers are valid or
not. (4) i) oabb ii) a_bc iii) *xyz iv) abcl23
(c) Explain any three escape sequence characters with suitable example. (3)
(d) Explain any three bit-wise operators with suitable example. (3)
2. (a) Write a program to generate Fibonacci series (1, 1, 2, 3, 5……..) for n no.
of terms with flowchart. (8)
(b) Write a C program to check whether the given two floating point nos are same
upto 2 decimal places. (8)
3. (a) Write a program to check whether a given string is palindrome or not with
flowchart. (10)
(b) If x, y and z are integer variables then evaluate the following expressions and
give the final values of x, y and z.
# -blankspace.
(b) Write a 'C prog, to display and cont no. of vowels in a given string with
flowchart. (8)
ii) i = 0;
Section II
(d) Show the use of > and >> redirection operators in unix. (4)
7. (a) Explain different types of storage classes with example. (8) (b)
Explain recursion using example. (8)
Give user defined function for each of the above operation. (10)
(d) Write a 'C’ Prog to declare a structure for employee record having name,
employee code and salary. Read in the information for 30 employee and list
employee and list employees having salary greater than 10,000. (6)
(a) main( ) .
inta,b,*P1,*P2,x,y;
x = *P1 * *P2-6;
*P1=*P1+*P2;
y=(*P1/P2)+10;
(b) main( )
intx=10, y=20, P, g;
(c) main ( )
Printf("% d",m);
m = m + 5;
(d) main ( )
charx=7;
x<< 1;
N. B.:
Section I
1. i) What are the security rights associated with files and directories in UNIX ?
(3)
ii) Write range of long signed int, double and unsigned char. (3)
main ( )
floaty =24.5874;
printf("% 7.4f",y);
printf("% -7.2f",y);
printf("% 10.2e",y);
(a) Write commands at UNIX prompt $ for the following: (any six):- (6)
vi) Tomove'yourfile".
ii) Write a recursive function ? 'Rev' to reverse a number entered by the user.
(7)
(a) The following set of numbers is popularly known as 'Pascal's triangle. (10)
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
If we denote rows by i and columns by j , then any element (except the boundary
elements) in the triangle is given by - Pij =Pi-1,j-1 +Pi-1 , j
Write a program to calculate the elements of the Pascal triangle of 06 ' rows and
print the results.
(b) i) A square matrix that is, one having the same number of rows and
columns, is called a diagonal matrix if its only non-zero elements are on the
diagonal from upper left to lower right. Write a program that reads a matrix and
checks if it is diagonal matrix. (5)
ii) Write a program to find GCD and LCM for two numbers entered by user. (5)
ii) Write the C Program to count and to display total no of vowels contained in user
input string. (8)
z=y=x; if(a&&b>0.9)
y- = x--; printf("IFPART");
printf("y=%dz=%dx=%d"y,z,) }
main ( )
int * * ptr = p ;
www.techbirbal.com – Engineering the Future
www.techbirbal.com
printf("%d%d",a,**p); .
7. (a) Define a structure called cricket that will describe the following
information:-(10)
using cricket", declare an array player with 50 elements and write a program to
read the information about all 50 players. Sort the structure on there batting
average and print the results.
v) stcmp(S1,S2).
(ii) What is a union ? How does a union differ from a structure ? Explain with
suitable example.
N. B.:
1. (a) WAP to find GCD and LCM for two natural numbers entered by user. (5)
(c) WAP to find the octal equivalent of the natural number entered by the user.
(5)
(d) Write commands at UNIX prompt $ for the following: (5) i) To change
the individual file ownership.
(b) WAP to find the largest and the second largest elements in the list entered by
the user. (8)
(c) Explain the following functions : (4) (i) Ceil () (ii) sqrt () (iii) fmod ()
(iv) strcpy ()
(b) Design a structure "st" to contain name, date of birth and total marks
obtained. Define the structure "dob" to represent date of birth. WAP to read data for
n students in a class and sort them in descending order of total marks. (12)
(c) What are the security rights associated with files and directories in UNIX?
(4)
symmetric if its transpose equals to matrix itself. v) To find sum of all the elements
lying above the main diagonal.
5. (a) WAP using recursive function for finding the value of y where y = x", x
(b) WAP that deletes the duplicates in the set of numbers entered by the user
and prints the list without duplicates.
7. (a) WAP to read two natural numbers r1 and r2, where r2 is greater than r1,
and to generate all the prime numbers between r1 and r2 both inclusive.
(8)
(b) Write a function to find factorial of a number. WAP to find value of BIO using
this function, where BIO is defined as - (8)
main ()
{ int x=5,y,z; ,
z = y = x;
y- = --x;
z- = x --;
x-=--x-x--;
(c)
Write a function to find factorial of a number. WAP to find value of BIO using this
function, where BIO is defined as - (10)
2. (a) WAP using recursive function for finding the value of y wherey = xn, x
and y are real numbers and 'n' is a natural number. (10)
(b) WAP to find the largest and the second largest elements in the list entered by
the user. (10)
3. (a) What is an Union ? How does it differ from a structure ? Explain with
suitable example. (5)
(b) Comment with suitable examples on the following operators used in printers
in C:- i) & ii) *. (5)
(c) WAP to input data into an array. Compute the sum and average. Then count
the number of valves of the array greater than average and the number of valves
less than the average. Print the values, the average and the average and the two
counts. (10)
4. (a) Write a recursive function to find the GCD of two numbers using
following recursive algorithm: - (10)
GCD(p, q) = p if q=o
(b) Define a structure called cricket the will describe the following information -
WAP that will store information of 100 players using this structure, also arrange and
display names of these players in descending order with respect to batting average.
(10)
(c) WAP to count and to display total number of vowels contained in user input
string.(5)
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
(b) Given a number, WAP using while loop to reverse the digits of the number, e.g.
if number is 3 1 2 4 1 then output will be 1 4 2 1 3. (10)
(d) Explain the following with suitable example - (4) i) Break ii)
Continue.