Ad Code

Responsive Advertisement

Solved Question Paper : MGKVP BCA I 2021, Programming Principles & Algorithm (PPA)

Solved Question Paper : MGKVP BCA I 2021, Programming Principles & Algorithm (PPA)

*****************

Solved Question Paper : MGKVP BCA I 2021, Programming Principles & Algorithm (PPA)




1.   Explain why C is known as a 'functional' language. Show how functions are used as building blocks in C.

Answer :

C is often considered a "functional" language because it emphasizes the use of functions as building blocks of programs. Functions are used to break down complex problems into smaller, more manageable pieces. This approach allows for code that is easier to understand, modify, and maintain.

In C, functions are defined using the following syntax:

return_type function_name(argument_list) {

    // function body

}

The return_type specifies the data type of the value that the function will return, while the function_name is the name of the function. The argument_list specifies the data types and names of any arguments that the function expects to receive.

Functions can be used in C in many ways. For example:

Modularization: Functions can be used to divide a program into smaller, more manageable pieces. Each function can be responsible for a specific task, which makes the overall program easier to understand and modify.

Code reuse: Functions can be reused in multiple parts of a program, which saves time and reduces the likelihood of errors.

Abstraction: Functions can be used to hide the details of a complex operation, making it easier for other parts of the program to use that operation without understanding its implementation details.

Recursion: C supports recursion, which is a technique that uses a function to call itself. This allows for elegant and concise code for certain types of problems, such as tree traversal.

Overall, functions are a fundamental building block of C programs. They allow for modularization, code reuse, abstraction, and recursion, making it easier to write, understand, and maintain complex programs.

/////////////////////////////////

2. 

2.  With examples, illustrate the different types of operators available in C language.

Answer:

In computer programming, operators are symbols or keywords that perform specific actions on one or more operands. There are several types of operators available in programming languages, each with a different purpose. Here are some examples of the different types of operators:

 

Arithmetic Operators: Arithmetic operators are used to perform mathematical operations on numeric values. Examples of arithmetic operators include:

Addition (+): Adds two operands together. For example, 2 + 3 = 5.

Subtraction (-): Subtracts one operand from another. For example, 5 - 3 = 2.

Multiplication (*): Multiplies two operands together. For example, 2 * 3 = 6.

Division (/): Divides one operand by another. For example, 6 / 3 = 2.

Modulus (%): Returns the remainder of a division operation. For example, 5 % 3 = 2.

Assignment Operators: Assignment operators are used to assign a value to a variable. Examples of assignment operators include:

Assignment (=): Assigns the value on the right-hand side to the variable on the left-hand side. For example, x = 3 assigns the value 3 to the variable x.

Addition assignment (+=): Adds the value on the right-hand side to the variable on the left-hand side. For example, x += 2 is equivalent to x = x + 2.

Subtraction assignment (-=): Subtracts the value on the right-hand side from the variable on the left-hand side. For example, x -= 2 is equivalent to x = x - 2.

Comparison Operators: Comparison operators are used to compare two values and return a boolean result (either true or false). Examples of comparison operators include:

Equal to (==): Returns true if the two operands are equal. For example, 2 == 2 returns true.

Not equal to (!=): Returns true if the two operands are not equal. For example, 2 != 3 returns true.

Greater than (>): Returns true if the left operand is greater than the right operand. For example, 3 > 2 returns true.

Less than (<): Returns true if the left operand is less than the right operand. For example, 2 < 3 returns true.

Logical Operators: Logical operators are used to combine two or more conditions and return a boolean result. Examples of logical operators include:

AND (&&): Returns true if both conditions are true. For example, (2 > 1) && (3 > 2) returns true.

OR (||): Returns true if at least one condition is true. For example, (2 > 1) || (2 < 1) returns true.

NOT (!): Inverts the result of a boolean expression. For example, !(2 > 1) returns false.

These are just a few examples of the types of operators available in programming languages. Different programming languages may have additional or different types of operators, but the basic concepts remain the same.

/////////////////

3.

3.      Differentiate between

(a    printf() and scan()

(b    getchar() and putchar()

(c    #define and #include

 Answer:

(a printf() and scanf():

 

The printf() function is used to print formatted output on the screen or any output device. It takes a format string and any number of arguments, and it formats and prints the arguments according to the format string. It is often used to display messages, variables, and results of calculations on the console.

On the other hand, the scanf() function is used to read input from the user or a file. It takes a format string and one or more pointers to variables, and it reads input from the user or file and assigns the values to the variables based on the format string. It is commonly used to get input from the user for calculations or other purposes.

(b   getchar() and putchar():

 

The getchar() function is used to read a single character from the input stream, such as the keyboard or a file. It waits for the user to input a character, and then returns that character as an integer value. It is often used in loops to read a series of characters from the user until a certain condition is met.

 

The putchar() function is used to print a single character to the output stream, such as the console or a file. It takes a character as an argument, and then prints that character to the output stream. It is often used in loops to print a series of characters to the console or file.

(c    #define and #include:

 

The #define directive is used to create a constant or a macro in C programming. It is used to give a name to a value or a code snippet so that it can be used throughout the program without having to rewrite the value or the code snippet each time. For example, #define PI 3.14159 creates a constant named PI with a value of 3.14159.

The #include directive is used to include header files in C programming. It is used to add the contents of a header file to the current source file so that the functions, variables, and constants defined in the header file can be used in the current source file. For example, #include <stdio.h> includes the standard input/output library header file, which provides functions such as printf() and scanf().

////////////////

4.

Write about the different decision making structures with example in c programming language words.

Answer:

In C programming language, there are several structures that can be used for decision making. These structures allow the programmer to make decisions based on certain conditions and execute code accordingly. Here are some of the most commonly used decision making structures in C programming:

If statement: The "if" statement is used to execute a block of code if a certain condition is true. For example:

int x = 10;

if (x > 5) {

    printf("x is greater than 5");

}

In this example, the "if" statement checks if the value of x is greater than 5, and if it is, it executes the printf statement.

If-else statement: The "if-else" statement is used to execute one block of code if a certain condition is true, and another block of code if the condition is false. For example:

 

int x = 10;

if (x > 5) {

    printf("x is greater than 5");

} else {

    printf("x is less than or equal to 5");

}

In this example, if the value of x is greater than 5, the first printf statement is executed, and if it is less than or equal to 5, the second printf statement is executed.

Switch statement: The "switch" statement is used to execute different blocks of code based on the value of a variable. For example:

int x = 2;

switch (x) {

    case 1:

        printf("x is 1");

        break;

    case 2:

        printf("x is 2");

        break;

    case 3:

        printf("x is 3");

        break;

    default:

        printf("x is not 1, 2, or 3");

}

In this example, the "switch" statement checks the value of x and executes the block of code that corresponds to the value. If x is 1, the first printf statement is executed, if it is 2, the second printf statement is executed, if it is 3, the third printf statement is executed, and if it is any other value, the default printf statement is executed.

In conclusion, these decision making structures in C programming allow programmers to make decisions based on certain conditions and execute code accordingly, making their code more flexible and adaptable to different situations.

////////////////////

5.

Write a program in c for determining whether a number is prime number or not.

Answer:

#include <stdio.h>

int main() {

    int num, i, isPrime = 1;

    printf("Enter a number: ");

    scanf("%d", &num);

 

    if (num <= 1) {

        isPrime = 0;

    } else {

        for (i = 2; i <= num / 2; i++) {

            if (num % i == 0) {

                isPrime = 0;

                break;

            }

        }

    }

 

    if (isPrime == 1) {

        printf("%d is a prime number", num);

    } else {

        printf("%d is not a prime number", num);

    }

 

    return 0;

}

/////////////////////

6

Write a c program for computing the gcd of two integers M.N.

Answer:

#include <stdio.h>

int gcd(int m, int n) {

    int temp;

    while (n != 0) {

        temp = n;

        n = m % n;

        m = temp;

    }

    return m;

}

int main() {

    int m, n;

 

    printf("Enter two integers: ");

    scanf("%d %d", &m, &n);

    printf("GCD of %d and %d is %d\n", m, n, gcd(m, n));

    return 0;

}

///////////////////////

7.

Write a program in C to generate the sum S of the following series upto N terms , where N is to be supplied at run time.

S = 1 + 2 + 3 + 4 + 5 – – + N

Answer:

 

#include <stdio.h>

int main() {

    int n, i, sum = 0, sign = 1;

    printf("Enter the value of N: ");

    scanf("%d", &n);

 

    for (i = 1; i <= n; i++) {

        sum += i * sign;

        sign = -sign;

    }

    printf("Sum of the series is: %d\n", sum);

    return 0;

}

//////////////////////////

8.

Discuss briefly about the different problem solving techniques for designing a software solution to a specified problem.

Answer:

Designing a software solution for a specified problem requires the use of various problem-solving techniques. There are some of the commonly used techniques:

 

Divide and Conquer: This technique involves breaking a complex problem down into smaller, more manageable subproblems, solving each subproblem independently, and then combining the solutions to obtain the final result. This technique is commonly used in algorithm design and is especially useful for problems that can be parallelized.

 

Dynamic Programming: This technique involves breaking a problem down into smaller subproblems and solving each subproblem once, storing the results in memory, and reusing those results to solve larger subproblems. This technique is useful for problems that exhibit overlapping subproblems and can help reduce the time complexity of an algorithm.

 

Backtracking: This technique involves recursively trying different solutions to a problem and undoing the previous solution if it does not lead to a valid solution. This technique is useful for problems that require finding all possible solutions or for problems with constraints that limit the possible solutions.

 

Brute Force: This technique involves systematically trying all possible solutions to a problem and selecting the one that meets the desired criteria. This technique is useful for small problems or problems with a small solution space.

 

Greedy Algorithms: This technique involves making locally optimal choices at each step of the problem in the hope of finding a global optimum. This technique is useful for problems that exhibit the greedy-choice property, where a locally optimal choice leads to a globally optimal solution.

 

Heuristics: This technique involves using a set of rules or guidelines to guide the search for a solution. This technique is useful for problems that do not have a known algorithmic solution or for problems with a large solution space.

 

///////////////////////

9.

What is the difference between an algorithm and a flowchart are the two different tool for the same activity draw a flowchart for finding the average of a set of numbers denoting the marks obtained by a class of students.

Answer:

An algorithm is a set of instructions that can be followed to solve a problem or perform a task. It is typically expressed in a programming language or pseudocode.

A flowchart, on the other hand, is a graphical representation of an algorithm. It uses various symbols to represent the steps involved in solving a problem or performing a task. Flowcharts are often used to communicate the steps of an algorithm visually, making them easier to understand and follow.

 

While algorithms and flowcharts are related, they are not the same thing. An algorithm is a logical sequence of steps, while a flowchart is a visual representation of that sequence. A flowchart can be used to illustrate an algorithm, but an algorithm can also be expressed in other ways, such as through a programming language.



Post a Comment

0 Comments