1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

First Year B.C.A.(Sem 1) March/April – 2011 – Computer Programming and Programming Methodology

Discussion in 'Question Papers' started by ahmedsabuwala12, Sep 21, 2016.

  1. ahmedsabuwala12

    ahmedsabuwala12 New Member

    Joined:
    Aug 25, 2016
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    First Year B.C.A. (Sem 1) (CBCS) Examination
    March/April – 2011
    Computer Programming and Programming Methodology
    [Total Marks: 70] ​
    [1] Answer In Short:

    (1) How we can convert a number to a string?
    Ans.
    Code:
    main()
    {
        int a = 10;
        char s[10];
        itoa(a,s,10);
        printf("%s", s);
        getch();
    }
    
    (2) What is computer program?
    Ans. A computer program is a set of instructions that performs a specific task when executed by a computer. A computer requires programs to function, and typically executes the program's instructions in a central processing unit.

    (3) What is the range of values for BASIC variable that is declared of the data type LONG?
    Ans. LONG 4 bytes -2,147,483,648 to 2,147,483,647

    (4) What do you mean by self-replacement technique?
    Ans. This technique extensively used in counting the number of repetitive operations performed by the computer. It can be used to generate a new value of a variable based on its previous value.

    (5) Write LET statement for the following:
    formula.png

    Ans. formula 2.png

    (6) Write a different ways of writing comments in BASIC program.
    Ans. The syntax for a comment is:
    Single line :
    //comment goes here

    Multi line :
    /*
    comment goes here
    */
    (7) Can we change the value of control variable in FOR loop?
    Ans. Yes

    (8) Give difference between forward and backward jumping.
    Ans. Forward jumping go to next place in the program and continue execution there.
    Backward jumping jumps to previous place in the program.

    (9) Write a purpose of SGN () and ABS() function.
    Ans. SGN ():
    Returns an integer indicating the sign of a number.

    Syntax:
    Sgn(number)

    ABS ():
    It returns absolute value of given argument.

    Syntax:
    Datatype abs(var name/value);

    (10) What is syntax error? Give example.
    Ans. A line is encountered that contains an incorrect sequence of characters such as unmatched parentheses, a misspelled command or statement, incorrect punctuation, using variable without declaration.
    Example:-
    int a, b:
    The above statement will produce syntax error as the statement is terminated with : rather than ;



    [2] Explain following. (Any three) 15

    (1) Different level of programming language.
    Ans. Programming language that can be directly understood by a machine without conversion.
    Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.
    Languages are designed to be machine – independent.
    Program lang.png

    There are two types of programming language :-
    1 - Low Level Language or Machine Oriented Language
    2 - High Level Language or Problem Oriented Language

    1 - Low Level Language or Machine Oriented Language :
    • The set of symbolic instruction codes usually in binary form that is used to represent data in a machine called machine languages.
    • This language is difficult to learn and use.
    • Languages are machine dependent.
    • Languages have been designed to give a better machine efficiency, i.e. faster program execution.
    • Low-level languages can convert to machine code without a compiler or interpreter.
    • A program written in a low-level language can be made to run very quickly.
    • Two good examples of low-level languages are assembly and machine code.
    • Languages such as C and C++ are considered "lower-level".

    2 - High Level Language or Problem Oriented Language:
    • A high-level programming language is a programming language with strong abstraction from the details of the computer.
    • It may use natural language elements.
    • Be easier to use.
    • Designed for a specific job.
    • Making the process of developing a program simpler and more understandable relative to a lower-level language.
    • Easier to understand.
    • It is more like human language and less like machine language.
    • e.g.: Java, Python, ML, Prolog, MATLAB, etc.


    (2) Arithmetic operator and order of evaluation.
    Ans. ht tp://w ww .go4expert.com/articles/mathematical-operations-c-t33390/

    Please visit above link.


    Order of evaluation:
    operator table.png

    (a + b) * (c + d) + e – f/g*h + 3.25
    Expressions comprise three kinds of entities. – Operators ( Operators (+, -, /, *). – Operands (a, b, c, d, e, f, g, h, 3.25, (a + b), (c + d), etc ). . – Delimiters ((, ))

    (3) Read, Data and Restore.
    Ans.
    READ Statement:
    Purpose:
    To read values from a DATA statement and assign them to variables.
    Syntax:
    READ list of variables
    Example:
    Code:
        80 FOR I=1 TO 10
        90 READ A(I)
        100 NEXT I
        110 DATA 3.08, 5.19, 3.12, 3.98, 4.24
        120 DATA 5.08, 5.55, 4.00, 3.16, 3.37
    
    DATA Statement:
    Purpose:
    To store the numeric and string constants that are accessed by the program READ statement.
    Syntax:
    DATA constants
    Example:
    Code:
        80 FOR I=1 TO 10
        90 READ A(I)
        100 NEXT I
        110 DATA 3.08,5.19,3.12,3.98,4.24
        120 DATA 5.08,5.55,4.00,3.16,3.37
    
    RESTORE Statement:
    Purpose:
    To allow DATA statements to be reread from a specified line.
    Syntax:
    RESTORE[line number]
    Examples:
    Code:
        
         10 READ A, B, C,
         20 RESTORE
         30 READ D, E, F
         40 DATA 57, 68, 79
    
    (4) Benefits and limitations of drawing flowchart.
    Ans. Advantages of Using FLOWCHARTS:

    • Communication:
    Flowcharts are better way of communicating the logic of a system to all concerned or involved.

    • Effective analysis:
    With the help of flowchart, problem can be analyzed in more effective way therefore reducing cost and wastage of time.

    • Proper documentation:
    Program flowcharts serve as a good program documentation, which is needed for various purposes, making things more efficient.

    • Efficient Coding:
    The flowcharts act as a guide or blueprint during the systems analysis and program development phase.

    • Proper Debugging:
    The flowchart helps in debugging process.

    • Efficient Program Maintenance:
    The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.

    Disadvantages of Using FLOWCHARTS:

    • Complex logic:
    Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex. This will become a pain for the user, resulting in a waste of time and money trying to correct the problem.

    • Alterations and Modifications:
    If alterations are required the flowchart may require re-drawing completely. This will usually waste valuable time.

    • Reproduction:
    As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.


    [3] Attempt any three: (15)

    (1) Write a note on various methods to store a value in variable.
    Ans. Int a=10
    Int *b = &a
    Int c =&a

    (2) Explain SELECT CASE statement with an example.
    Ans. SELECT CASE is used to determine the program flow by comparing the value of a variable to specific CASE values.

    Syntax:
    SELECT [EVERY]CASE checkvalue
    CASE
    CASE IS
    CASE ELSE
    END SELECT

    Example:
    Code:
    INPUT "Enter a whole number value from 1 to 40: ", value
    value1 = 10
    value2 = 20
    value3 = 30
    
    SELECT CASE value
      CASE value1: PRINT "Ten only"
      CASE value1 TO value2: PRINT "11 to 20 only" '10 is already evaluated
      CASE value1, value2, value3: PRINT "30 only" '10 and 20 are already evaluated
      CASE IS > value2: PRINT "greater than 20 but not 30" '30 is already evaluated
      CASE ELSE: PRINT "Other value" 'values less than 10
    END SELECT  
    
    (3) What is LOOPING? Write down syntax of FOR....NEXT loop and define following in relation to a FOR...NEXT loop:
    1 – Control variable
    2 – Initial value
    3 – Final value
    4 – Step
    Ans. A loop is a way of repeating a statement a number of times until some way of ending the loop occurs.

    Syntax:
    for ( init; condition; increment ) {
    statement(s);
    }

    Example:
    Code:
    #include <stdio.h>
     void main ()
     {
          int a;
          // for loop execution 
          for( a = 10; a < 20; a++ )
        {
                printf("value of a: %d\n", a);
          }
    }
    
    When the above code is compiled and executed, it produces the following result −
    value of a: 10
    value of a: 11
    value of a: 12
    value of a: 13
    value of a: 14
    value of a: 15
    value of a: 16
    value of a: 17
    value of a: 18
    value of a: 19


    (4) Write a short note on debugging.
    Ans.
    Debugging is the routine process of locating and removing computer program bugs, errors which is handled by software programmers.
    Debugging checks, detects and corrects errors or bugs to allow proper program operation according to set specifications.
    Debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code.
    Debugging is a necessary process in almost any new software or hardware development process.

    The Debugging Process:
    debug.png

    [4] Do as direct: (15)
    (1) Find out error (if any) otherwise gives output for the following code:
    (any five)
    I. Print ASC(“hello”)
    II. Print SQR ((LEN(MID$(“GUJARAT”,2,3)))
    III. A=2.3
    PRINT LEN (A)
    IV. PRINT 8\3
    V. PRINT SGN (LEN (“VAPI”)-LEN (“SURAT”))
    VI. PRINT LEFT$ (“SURAT”, 3) +RIGHT$ (“RAJ”, 2)

    Ans.

    I. prints 72 (the ASCII value of h)
    II. 1
    III. 3
    IV. 2.67
    V. 1
    VI. SURAJ



    (2) What do you mean by “double subscripted variables”? Discuss its application.

    Ans. Tables or arrays that require two subscripts to identify a particular element are called double subscripted arrays.
    Two dimensional array or double subscripted variable: Arrays whose variables are specified by two subscripts.
    To create arrays of arrays known as two dimensional arrays.

    Syntax:
    type name[size1][size2]...[sizeN]

    For example:
    Float a [2][6];

    Example:
    Code:
        
    #include<stdio.h>
    #include<conio.h>
    main()
    {
        int arr[3][3], i, j;
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                printf("Enter the value for A[%d][%d]:",i,j);
                scanf("%d", &arr[i][j]);
            }
     }
        getch();
    }
    

    OR

    (2) What is sorting? Explain with example.
    Ans.

    • Sorting is nothing but storage of data in sorted order; it can be in ascending or descending order.
    • Sorting arranges data in a sequence which makes searching easier.
    • Every record which is going to be sorted will contain one key.
    • Based on the key the record will be sorted.
    • For example, suppose we have a record of students, every such record will have the following data:
    Roll No.
    Name
    Age
    Class
    Here Student roll no. can be taken as key for sorting the records in ascending or descending order. Now suppose we have to search a Student with roll no. 15, we don't need to search the complete record we will simply search between the Students with roll no. 10 to 20.

    Example of Bubble sort:

    --Sorting an integer array

    Code:
     
    #include<stdio.h>
    #include<conio.h>
    main()
    {
        int a[5], i, j, temp;
        for(i=0; i<5; i++)
        {
            printf("Enter number:");
            scanf("%d", &a[i]);
        }      
        for (i=0; i<5-1; i++)
        {
            for (j=i+1; j<5; j++)
            {
                if(a[i]>a[j])
                {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        for(i=0; i<5; i++)
        {
            printf("%d", a[i]);
        }
        getch();
    }
    
    (3) Write one or more basic statement:
    Dimension an array A of 100 cells.
    Dimension 100*200 matrix X
    Calculate a(1,1) * a(2,2) * a(3,3)......a(M,M)
    (code only)

    Ans.

    I. 100
    II. 20000
    III.
    Code:
    X=7;
        for (i=0; i<M; i++)
        {
            X=x*a (1, i)
        }
    

    [5] Attempt any three: (15)

    (1) Write a program to display all odd numbers between two limits.
    Ans.
    Code:
    #include <stdio.h>
    
    void main()
    {
        int i, n;
         
        printf("Print odd numbers till: ");
        scanf("%d", &n);
    
        printf("All odd numbers from 1 to %d are: \n", n);
    
        for(i=1; i<=n; i+=2)
        {
            printf("%d\n", i);
        }
    } 
    
    (2) Write a program to find a Roots of Quadratic equation.
    Ans.
    Code:
    #include <stdio.h>
    #include <math.h>
    main()
    {
        double a,b,c,root1,root2;
        printf(" Please enter a \n");
        scanf("%lf",&a);
        printf(" Please enter b \n");
        scanf("%lf",&b);
        printf(" Please enter c \n");
        scanf("%lf",&c);
        if (b*b-4.*a*c>0)
        {
            root1 = (-b + sqrt(b*b-4.*a*c) ) / (2.*a);
            root2 = (-b - sqrt(b*b-4.*a*c) ) / (2.*a);
            printf("\n First root is %lf ",root1);
            printf("\n Second root is %lf ",root2);
        }
        else
        {
            printf("\n Discriminate is negative! No roots!");
        }
        printf("\n ");
       
        getch();
    }
    
    (3) Write a program to calculate the value Fibonacci sequences for N names.
    Ans.
    Code:
    #include<stdio.h>
    #include<conio.h> 
    main()
    {
        int f=0,s=1,third,i,n;
        printf("Enter elements:");
        scanf("%d", &n);
        printf("\n%d %d",f,s);
        for(i=2;i<n;i++)
        {
            third=f+s;
            printf(" %d",third);
            f=s;
            s=third;
        }
       
    }
    
    (4) Write a program to display whether input M by N matrix is an identity matrix or not.
    Ans.
    Code:
    #include <stdio.h>
    void main()
    {
        int A[10][10];
          int i, j, R, C, flag =1;
          printf("Enter the order of the matrix A\n");
          scanf("%d %d", &R, &C);
          printf("Enter the elements of matrix A\n");
          for(i=0; i<R; i++)
          {
                for(j=0; j<C; j++)
                {
                scanf("%d",&A[i][j]);
                }
           }
       printf("MATRIX A is\n");
       
       for(i=0; i<R; i++)
      {   
            for(j=0; j<C; j++)
            {
            printf("%3d",A[i][j]);
            }
            printf("\n");
      }
        /* Check for unit (or identity) matrix */
        for(i=0; i<R; i++)
        {
            for(j=0; j<C; j++)
            {
            if(A[i][j] != 1 && A[j][i] !=0)
            {
                  flag = 0;
                  break;
            }
        }
       }
       if(flag == 1 )
       {
        printf("It is identity matrix\n");
       }
    else
    {
        printf("It is not a identity matrix\n");
    }
    
    Output:
    Enter the order of the matrix A
    2 2
    Enter the elements of matrix A
    2 2
    1 2
    MATRIX A is
    2 2
    1 2
    It is not a identity matrix

    (5) Write a program to merge the contents of two one dimensional arrays in third array.
    Ans.
    Code:
    #include<stdio.h>
    #include<conio.h> 
    main()
    {
        int x[3], y[2], z[5], i, j;
        for(i=0; i<3; i++)
        {
            printf("\n Enter Value A:");
            scanf("%d", &x[i]);
            z[i]=x[i];   
        } 
        for(j=0; j<2; j++)
        {
            printf("\n Enter Value B:");
            scanf("%d", &y[j]);
            z[i+j]=y[j];
        }
        for(i=0; i<5; i++)
        {
            printf("%d ",z[i]);   
        }
        getch();
    }
    
     

Share This Page