Home‎ > ‎

Assignment-4

CS101                                      Assignment-4                               2010-2011

 

PROGRAMMING IN C

 1.          

a.                   Draw a Flowchart for the following
The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional logic for generating reject letters for all candidates who do not get the required average & interview call letters for the others.

b.                  Explain the basic structure of C program.

2.          

a.                   Distinguish between getchar and scanf functions for reading strings.

b.                  What is the difference between signed integer and unsigned integer in terms of memory and range

3.          

a.                   What are the general characteristics of C?

b.                  Give and Explain the structure of a C program?

c.                   Write a C program to print the Pascal’s triangle.

 

4.         Write about space requirements for variables of different data types.

5.          

a.                   What is the difference between signed integer and unsigned integer in terms of memory and range

b.                  List the entire data types in C. What is the size of each of these data types

6.          

a.                   What is a string constant? How do string constants differ from character constants? Do string constants represent numerical Values?

b.                  Summarize the standard escape sequences in C. Describe them.

c.                   What is a variable? How can variables be characterized? Give the rules for variable declaration.

d.                  What is the purpose of type declarations? What are the components of type declaration?

7.          

a.                   What are different types of integer constants? What are long integer constants? How do these constants differ from ordinary integer constants? How can they be written and identified? 

b.                  Describe two different ways that floating-point constants can be written in C. What special rules apply in each case?

c.                   What is a character constant? How do character constants differ from numeric type constants? Do character constants represent numerical values?

8.          

a.                   What is meant by operator precedence? What are the relative precedence of the arithmetic operators?

b.                  What is the associatively of the arithmetic operators?

c.                   How can the value of an expression be converted to a different data types? What is this called?

d.                  What are unary operators? Explain example for each.

9.          

a.                   Explain the following & illustrate it with an example each.

                                            i.                        Increment & Decrement operator

                                          ii.                        Conditional operator.

                                        iii.                        Bitwise operator.

                                        iv.                        Assignment operator.

b.                  State the rules that applied while evaluating expression in automatic type conversion.

10.      

a.                   What is the purpose of break statement?

b.                  Suppose a break statement is included within the innermost of several nested control statements. What happens when break statement is executed?

c.                   Write a program to print the multiplication table up to 20 with proper format.

11.      

a.                   Write a program to determine and print the sum of the following harmonic series for a given value of n: 1+1/2+1/3+.....+1/n.

b.                  What are the logical operators used in C and illustrate with examples.

12.     Write a C program to print the lower triangular of a given square matrix

13.      

a.                   What do you mean by functions? Give the structure of the functions and explain about the arguments and their return values.

b.                  Write a C program that uses a function to sort an array of integers.

14.      

a.                   Distinguish between the following:

                                            i.                        Actual and formal arguments.

                                          ii.                        Global and local variables.

                                        iii.                        Automatic and static variables.

b.                  Explain in detail about pass by values and pass by reference. Explain with a sample program

15.      

a.                   Distinguish between formal variable and actual variable.

b.                  Distinguish between local and global variable.

c.                   Distinguish between call by value and call by reference.

16.      

a.                   What is a preprocessor directive.

b.                  Distinguish between function and preprocessor directive.

c.                   What is the significance of conditional compilation.

d.                  How does the undefining of a pre-defined macro done.

17.      

a.                   What are the advantages and disadvantages of recursion

b.                  Write a C program to find the factorial of a given integer using a function.

c.                   Write a recursive algorithm to compute the product of two non negative integers

18.      

a.                   Define recursion. What are the properties of recursive definition.

b.                  Write a recursive definition of a + b , where a and b are nonnegative integers, in terms of the successor function succ , defined as
succ(x)
int x;
{
return (x++);
}

19.     Let a be an array of integers. Present recursive algorithms to compute

a.                   Maximum element of the array

b.                  The sum of elements of the array.

20.      

a.                   Write a program to demonstrate passing an array argument to a function. Consider the problem of finding largest of N numbers defined in an array.

b.                  Write a recursive function power (base, exponent) that when invoked returns base exponent.

21.     Write a C program to find mean, standard deviation and variance of a set of elements

22.     The roots of a quadratic equation of the form ax2+bx+c = 0 are given by the following equations:
x1=-b+√(b2-4ac)/2a
x2=-b-√(b2-4ac)/2a
Write a function to calculate the roots. The function must use two pointer Parameters, one to receive the coefficients a,b and c and the other to send the roots to the calling function.

23.     Write a program that calculates the value of money at the end of each year of investment assuming an interest rate of 12 percent and prints the year & corresponding amount in two columns for a period of 10 years with an intial investment of 5 years. Formula: Value at end of year = value at start of year (1+interest rate)

24.     Write a non-recursive simulation of Towers of Hanoi problem.

25.      

a.                   In what way array is different from an ordinary variable?

b.                  What conditions must be satisfied by the entire elements of any given array?

c.                   What are subscripts? How are they written? What restrictions apply to the values that can be assigned to subscripts?

d.                  What advantage is there in defining an array size in terms of a symbolic constant rather than a fixed integer quantity?

e.                   Write a program to find the largest element in an array.

26.      

a.                   How are initial values written in a one-dimensional array definition? Is the entire array be initialized? What value is automatically assigned to those array elements not explicitly initialized?

b.                  Write a program to calculate mean, variance and standard deviation of n numbers.
     S=√ variance, where      Variance = 1/n Σ (xi-m)2      M= mean of n numbers.

27.      

a.                   Write a C program to do Matrix Multiplications.

b.                  Write in detail about one dimensional and multidimensional arrays. Also write about how initial values can be specified for each type of array

28.     The annual examination is conducted for 50 students for three subjects. Write a program to read the data and determine the following:

a.                   Total marks obtained by each student.

b.                  The highest marks in each subject and the Roll No. of the student who secured it.

c.                   The student who obtained the highest total marks.

29.      

a.                   What is a pointer? How is a pointer initiated? Give an example.

b.                  State whether each of the following statements is true or false. Give reasons.

                                            i.                        An integer can be added to a pointer.

                                          ii.                        A pointer can never be subtracted from another pointer.

                                        iii.                        When an array is passed as an argument to a function, a pointer is passed.

                                        iv.                        Pointers can not be used as formal parameters in headers to function definitions.

c.                   If m and n have been declared as integers and p1 and p2 as pointers to integers, then find out the errors, if any, in the following statements.

                                            i.                        p1 = &m;

                                          ii.                        p2 = n;

                                        iii.                        m=p2-p1;

                                        iv.                        *p1 = &n;

30.      

a.                   Explain the process of accessing a variable through its pointer. Give an Example.

b.                  Write a C program using pointers to read in an array of integers and print its elements in reverse order.

31.     Write a ‘C’ Program to compute the sum of all elements stored in an array using pointers.

32.      

a.                   Write a C program using pointer for string comparison.

b.                  Write a C program to arrange the given numbers in ascending order using pointers.

33.      

a.                   What is a pointer? List out the reasons for using pointers.

b.                  Write a C Program to illustrate the use of indirection operator “ * ” to access the value pointed by a pointer.

34.      

a.                   How to use pointer variables in expressions? Explain through examples.

b.                  Write a ‘C’ Program to illustrate the use of pointers in arithmetic operations.

35.      

a.                   Explain the process of declaring and initializing pointers. Give an example.

b.                  Write a C program that uses a pointer as a function argument.

36.      

a.                   What is a pointer? List out the reasons for using pointers.

b.                  Write a C Program to illustrate the use of indirection operator “*” to access the value pointed by a pointer.

37.      

a.                   Explain the process of accessing a variable through its pointer. Give an Ex- ample.

b.                  Write a C program using pointers to read in an array of integers and print its elements in reverse order.

38.      

a.                   How to use pointer variables in expressions? Explain through examples.

b.                  Write a ‘C’ Program to illustrate the use of pointers in arithmetic operations.

39.     Write a ‘C’ program using pointers to determine the length of a character string.

40.     Write a program to count the number of words, lines and characters in a text.

41.      

a.                   Distinguish between getchar and scanf functions for reading strings.

b.                  Write a program to count the number of words, lines and characters in a text.

42.     Write a C program to replace a particular word by another word in a given line of text.

43.      

a.                   How to compare structure variables? Give an example.

b.                  How does a structure differ from an array?

c.                   Distinguish between an array of structures and an array within a structure. Give an example each.

d.                  Differentiate between a structure and union with respective allocation of memory by the compiler. Given an example of each.

e.                   Describe nested structures. Draw diagrams to explain nested structure.

f.                   Distinguish between an array of structures and an array within a structure. Give an example each.

g.                  How are structure elements stored in memory.

44.      

a.                   What is structure within structure? Give an example for it.

b.                  Write a C program to illustrate the comparison of structure variables.

c.                   Explain the different ways of passing structure as arguments in functions.

d.                  What is the use of a structure? Given an example for a structure with initial- ized values.

e.                   Explain with an example how a structure can be organized in the ‘C’ language?

f.                   What are Bit fields. What are its advantages. What is its syntax.

45.      

a.                   Write a C program to illustrate the concept of structure within structure.

b.                  Write a C program to print maximum marks in each subject along with the name of the student by using structures. Take 3 subjects and 3 students records.

c.                   Write a C program to illustrate the method of sending an entire structure as a parameter to a function.

d.                  Write a C program to illustrate the comparison of structure variables.

e.                   What is the use of a structure? Given an example for a structure with initialized values.

f.                   Write a C program to store the information of vehicles. Use bit fields to store the status information. Assume the vehicle object consists of type, fuel and model member fields. Assume appropriate number of bits for each field.

46.      

a.                   Write a program to declare pointer as members of structure and display the contents of the structure. Define a structure object, boy with three fields: name, age and height.

b.                  Write a C program using structure to create a library catalogue with the following fields; Access number, author’s name. Title of the book, year of publication, publisher’s name, price.

c.                   Write a program to create an array of student structure objects and to find the highest marks scorer. The fields in the student structure are: name, age and marks.

d.                  Write a C program using structure to read and print the student’s records of a class with the following members.
       Field Name Data Type
       name string
       reg no integer
       major string
       result string

e.                   Write a C program using structure to create a library catalogue with the following fields; Access number, author’s name. Title of the book, year of publication, publisher’s name, price.

f.                   Define a structure type struct ABS, that contains name, age, designation, and salary. Using this structure, write a C program to read this information for one person from the keyboard and print the same on the screen.

g.                  Write a program to read n records of students and find out how many of them have passed. The fields are student’s roll no, name, mark and result. Evaluate the result as follows
if markes > 35 then
       Result = “Pass”
else
      “Fail” [10]

47.     Write a C program to compute the monthly pay of 100 employees using each employee’ s name, basic-pay. The DA is computed as 52% of the basic pay. Gross-salary (Basic pay +DA). Print the employees name and gross salary.

48.     Write a C program to read the information from the keyboard in which the “Employee” structure consists of employee name, code, designation and salary. Construct an array of structures that stores n employees information and write a program to carry out operations like inserting a new entry, deleting entry.

49.     The annual examination is conducted for 50 students for three subjects. Write a program to read the data and determine the following:

a.                   Total marks obtained by each student.

b.                  The highest marks in each subject and the Roll No. of the student who secured it.

c.                   The student who obtained the highest total marks.

50.      

a.                   What are the file I/O functions in C. Give a brief note about the task performed by each function.

b.                  Distinguish between text mode and binary mode operation of a file.

c.                   What is the task performed by fseek( ) function. What is its syntax. Explain each parameter in it.

d.                  Explain the command line arguments. What are the syntactic constructs followed in C.

e.                   Explain the way of defining, opening and closing a file. Also explain the different modes of operation.

f.                   How does an append mode differs from a write mode.

g.                  Compare between printf and fprint f functions.

51.      

a.                   Write a program to read an input file and count the number of characters in the input file.

b.                  Write a program to open a pre-existing file and add information at the end of file. Display the contents of the file before and after appending.  

c.                   Write a C program to read the text file containing some paragraph. Use fseek() and read the text after skipping n characters form beginning of the file.

d.                  Write a C program to read the input file from command prompt, using command line arguments.

e.                   Write a program to copy upto 100 characters from a file to an output array.

52.     Write a C program to read a text file and to count

a.                   number of characters,

b.                  number of words and

c.                   number of sentences and write in an output file.

53.     Write a C program to replace every 5th character of the data file, using fseek( ) command.

54.     Write a C program to read information about the student record containing stu- dent’s name, student’s age and student’s total marks. Write the marks of each student in an output file.

55.     Write a C program to read data from the keyboard, write it to a file called INPUT, again read the same data from the INPUT file, and display it on the screen.

56.     Write a program to read a C program file and count the following in the complete C program

a.                   Total number of statements

b.                  Total number of opening brackets.

Ċ
Kapil Sharma,
Nov 13, 2011, 2:05 AM
Comments