Cp Questions

download Cp Questions

of 7

Transcript of Cp Questions

  • 8/2/2019 Cp Questions

    1/7

    COMPUTER PROGRAMMING

    UNIT I

    SHORT ANSWER QUESTIONS

    1. What is Flowchart?2. What is Algorithm?

    ESSAY QUESTIONS

    1. Draw the block diagram of a computer and explain various components.2. Write an algorithm for finding biggest of given numbers.3. Write an algorithm to find the roots of quadratic equation for all the cases.

    UNIT II

    SHORT ANSWER QUESTIONS

    1. What is the purpose of break statement?

    2. What is the purpose of continue statement?

    3. What are constants?

    4. Define a variable? How to declare a variable in C?

    5. What is the output of the following code:

    int a=10,x;

    x=a++; printf(%d,x);

    x=++a; printf(%d,x);

    6. What is the difference between while and do while statement in c?

    ESSAY QUESTIONS

    1. What is meant by operator precedence?2. What is the relative precedence of the arithmetic operators?3. Write about space requirements for variables of different data types.

    (or)Name the different data types that C supports and explain them in detail.

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

    5. Explain the following and illustrate it with an example each.

  • 8/2/2019 Cp Questions

    2/7

    (i) Increment and decrement operator (ii) Conditional operator6. State the rules that apply while evaluating expression in automatic type

    Conversion.7. Explain using examples, the decision control structures such as if, if-else,

    Else-if ladder & switch statements with syntax.

    8. Given a number, write a program using while loop to reverse the digits ofthe number. For e.g. 12345 should be written as 54321.9. Write a program to print the multiplication table upto to with proper format.

    UNIT III

    SHORT ANSWER QUESTIONS

    1. Explain the effect of the following statements: int a, *b = &a;2. In what way an array is different from an ordinary variable?

    3. What advantage is there in defining an array size in terms of a symbolicconstant rather than a fixed integer quantity?4. What restrictions apply to values that can be assigned to subscripts?5. Explain the effect of the following statements: int x; a=(float*)&x;6. What conditions must be satisfied by the entire elements of any given

    array?7. What are subscripts? How are they written?8. What is a String?9. What is the use of malloc and calloc functions?

    ESSAY QUESTIONS

    1. Write a C program that uses a function to sort an array of integers.2. (a) What is a pointer? How is a pointer initiated? Give an example. List out

    the reasons for using pointers.(b) State whether each of the following statements is true or false. Givereasons.

    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 pointeris passed.iv. Pointers can not be used as formal parameters in headers tofunction definitions.

    (c) If m and n have been declared as integers and p1 and p2 as pointersto 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;

    3. Write a C program to perform multiplication of two given matrices.4. What is an array? What are different types of array? Explain declaration

    and initialization of arrays.

  • 8/2/2019 Cp Questions

    3/7

    5. What is string? Explain about string handling functions.

    UNIT IV

    SHORT ANSWER QUESTIONS

    1. Distinguish between the Global and local variables.2. Distinguish between the Automatic and static variables.3. Distinguish between Actual and formal arguments.4. Define a Macro. Give an example.5. What is recursion?6. What is the use of return statement?

    ESSAY QUESTIONS

    1. Explain the detail about pass by value and pass by reference. Explainwith sample program.2. a) What do you mean by functions?

    b) Give the structure of the functions and explain about the arguments andtheir return values.

    3. Explain the working of recursion with an example.4. Write a C program to print pascal triangle.5. Write a C program to solve towers of Hanoi.

    UNIT V

    SHORT ANSWER QUESTIONS

    1. What is a structure? How it is initialized?

    2. Explain the command line arguments.

    3. What is the difference between structure and union?4. What is structure pointer?5. What is the difference between text and binary files?6. Explain the advantages of structure type over the array type variable.

    ESSAY QUESTIONS

    1. Define a structure in C. Explain clearly with suitable examples various

    components of a structure, declaring structure variables, initializing,

    accessing them, passing them as arguments to and returning them from

    functions.

  • 8/2/2019 Cp Questions

    4/7

    2. Define structure student with roll number, name, and marks as members

    and define functions to read and print data of a student.

    3. Elaborately discuss about the file handling functions in C.

    4. Write a program to copy a file into another, the names of the functionbeing given at the command prompt.

    5. Write short notes on the following

    a. fseek()

    b. ftell()

    c. feof()

    d. rewind()

    6. How are structure elements stored in memory? What is a structure within

    structure? Give an example.

    UNIT VI

    SHORT ANSWER QUESTIONS

    1. What is a preprocessor directive?

    2. What is meant by file inclusion?3. What is linked list?

    4. What is the purpose of condion compilation?

    ESSAY QUESTIONS

    1. a) Explain linked list. Discuss the advantages of linked lists over arrays in insertion

    and deletion of an element.

    b) Write functions to insert and delete an element from a linked list.

  • 8/2/2019 Cp Questions

    5/7

    Write a C Program to solve towers of hanoi.

    #include "stdio.h"#include "conio.h"void toh(int,char,char,char);void main(){

    int n;printf("\n Enter no.of disks:");scanf("%d",&n);toh(n,'A','C','B');

    getch();}void toh(int n,char f,char l,char m){

    if(n){

    toh(n-1,f,m,l);printf("\n%d disk is moved from %c to %c",n,f,l);toh(n-1,m,l,f);

    }}

  • 8/2/2019 Cp Questions

    6/7

    Write a C program to sort an array of integers .

    #include void read(int a[],int n){

    int i;printf("\n Enter elements :");for(i = 0; i < n; i++)

    scanf("%d",&a[i]);}void display(int a[],int n){

    int i;printf("\n The elements are :");for(i = 0; i < n; i++)

    printf("%5d",a[i]);}void bsort(int a[],int n){

    int i,j,temp;for(i = n-2; i >=0; i--){

    for(j = 0;j a[j+1]){

    temp = a[j];a[j] = a[j+1];a[j+1] = temp;

    }}

    }}

    void main(){

    int a[50],i,n;char ch;printf("\n Enter no.of elements : ");scanf("%d",&n);read(a,n);printf("\nElements before sort :\n");display(a,n);

  • 8/2/2019 Cp Questions

    7/7

    bsort(a,n);printf("\n Elements after sort :\n");display(a,n); getch();}